Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArrayList and casting

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
0
0
US
Hello,

I'm trying to use the BufferedWriter class to write files to a text file via an ArrayList of strings. Unfortunately I run into a compile-time error about not being able to resolve symbols. Is this a casting issue? Here's the snippet of code I have:


FileWriter wr = new FileWriter(outFileName);
BufferedWriter outFile = new BufferedWriter (wr);

for(int i = 0; i < Stringlist.size(); i++)
{
outFile.write(Stringlist.get(i));
outFile.newLine();
}



I think the &quot;get&quot; method returns an object, but I need a string to make this work. I tried casting the object into a string but I find that it doesn't write anything to the text file. Does anyone have any suggestions?

Thanks,
Jisoo22
 
The Full code is needed.....along with the exception and also the line number if the code is too long
I think the problem is in imported class or package if any....
 
in short (see your other post on the same question for a longer answer)
.get returns an object
.write expectes a String input

cast what .get gives you into a string so the .write will write it -------------------------------------------
There are no onions, only magic
-------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top