• Post Reply Bookmark Topic Watch Topic
  • New Topic

Save a textfile, using text from LinkedList  RSS feed

 
aram naderi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I need to save a bunch of text to a txt file from a LinkedList.

Here's the code.



I'm just beginning with Java, and thats as far as I've been able to go.

The names inside names.txt are these, create a text file with these in it :

Aram
Tommy
Xavier
Zam
Johan
Johan
Rasmus

Basically, the program should read from Names.txt, save the names to a LinkedList, and then using the LinkedList, print them all out to the cmd screen, and THEN it should also save the names into a NEW txtfile.

Please help.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some small remarks:

Variables should start with a lowercase letter.
Close your resources (the BufferedReader).

What is the problem? Why not just look through them and output them?
You know how to read from a file and writing to a file isn't that much harder.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Javaranch!
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also indent your code more carefully. It will then look like thisUse spaces not tabs for indentation. Get a decent text editor eg NotePad++ Notepad2 or jEdit, which will automatically convert tabs to (4) spaces and help with indents, bracket matching, etc. That makes finding errors much easier.

I would prefer to get rid of the break like this
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!