• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Save a textfile, using text from LinkedList

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Javaranch!
 
Marshal
Posts: 76419
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic