Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how would I use print writer and file reader properly on an arraylistwith arraylist inside?

Thread Tools

how would I use print writer and file reader properly on an arraylistwith arraylist inside?

Posts: n/a
Hi again,

I have an ArrayList<Word> which creates a new word with an ArrayList
of its definitions..

I am trying to use readfile and writefile to save and load the words
and definitions made by the user. It saves and loads, yes. However, it
is not properly saved and loaded. I want to save the word with
definitions as is and load it as is (so the user can still update the
words definitions or add some words). I am not very familiar with
PrintWriter and FileReader, I've been studying it for the past two
weeks and all I can do is save and load an array.


I have..

1. word
[hello, word, thanks, again]

-- this is the word and its definitions.

after I save.. and load it again.. this shows

1. word
3. [hello, word, thanks, again]

here is my code for load and save.

public void saveFile(ArrayList<Word> array)
throws IOException
PrintWriter out = new PrintWriter ("initlist.txt");
for (int ctr = 0; ctr < array.size(); ctr++)



public void loadFile(ArrayList<Word> array)
throws IOException
FileReader f = new FileReader ("initlist.txt");
Scanner input = new Scanner (f);
ArrayList<String> tempDef;
while (input.hasNextLine())
String word = input.nextLine();

if (array.contains(word)==false)
Word temp = new Word(word);
tempDef = new ArrayList<String>();

for (int aCtr = 0; aCtr < tempDef.size(); aCtr++)




I've been trying to fix this, I just can't

Maybe anyone knows. Thanks.
Reply With Quote
Posts: n/a
On Nov 12, 2:55*pm, justineee <(E-Mail Removed)> wrote:

> * * tempDef = new ArrayList<String>();
> * * *for (int aCtr = 0; aCtr < tempDef.size(); aCtr++)
> * * *{
> * * * temp.addDefinition(tempDef.get(aCtr));
> * * *}

You have a bug there, you've just initialized tempDef to a new empty
ArrayList, and try to iterate over it. No temp.addDefinition(..) will
be performed.

That's a start. (And it doesn't mean that without this bug the rest is
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Samsung DVD reader/CD Reader/writer SM-352 Yeah Right NZ Computing 35 02-13-2008 09:25 AM
what' wrong with my simple codes on reader/writer problem ,the writer thread never run DaVinci Java 1 10-05-2006 07:42 AM
Can you change a dvd combo (cd writer/ dvd reader) into a dvd writer using just software?? DVD Video 3 03-31-2006 05:12 PM
Isn't DataGrid.Render(writer) supposed to automatically call RenderBeginTag(writer) and RenderEndTag(writer)? Henri ASP .Net Building Controls 1 07-13-2004 10:27 PM