Hello,
I have a problem with an ArrayList. My program is supposed to take all the elements of that array and write them to a text file. Unfortunately it doesn't. I think it may be a casting issue as ArrayList's get method only returns objects. But after casting those objects into strings, still no go. Here's a little snippet of my code below. Does anyone have any ideas?
Thanks,
Jisoo22
I have a problem with an ArrayList. My program is supposed to take all the elements of that array and write them to a text file. Unfortunately it doesn't. I think it may be a casting issue as ArrayList's get method only returns objects. But after casting those objects into strings, still no go. Here's a little snippet of my code below. Does anyone have any ideas?
Thanks,
Jisoo22
Code:
public static void saveModel(String outFileName, ArrayList stringList)
{
ArrayList list = stringList;
try
{
FileWriter wr = new FileWriter(outFileName);
BufferedWriter outFile = new BufferedWriter (wr);
for(int i = 0; i < list.size(); i++)
{
outFile.write((String)list.get(i)); // <---- It looks to be this is the culprit. Somehow
// <---- the elements of stringArray do not get written
// <---- to the new text file despite being cast as
// <---- strings for the stringBuffer's write method.
// <---- How does this work???
outFile.newLine();
}
}
catch(Exception e)
{
System.out.println(e);
}
}//saveModel