wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Saving to a txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Saving to a txt file" Watch "Saving to a txt file" New topic
Author

Saving to a txt file

Steve Shipman
Greenhorn

Joined: Mar 28, 2006
Posts: 27
Ive got my program, it works exactly how I want it to, I just need to save my results into a text file, and ive tried a few different ways that I found on the internet and my book but none worked correctly. This is my code:



in main I have "System.out.println(list);" that prints my linkedlist, which is want to save into a text file called "LuckyNumbers.txt"....I just cant get it right, the stuff I have tried isnt working....I might have been putting it in the wrong place, I was putting it in the main method. Anyway, thanks for the help guys.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078


Keep in mind this is a really bad way of doing it, but for your simple example it's probably sufficient.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Steve Shipman:
...I have "System.out.println(list);" that prints my linkedlist, which is want to save into a text file called "LuckyNumbers.txt"...

You could try a simple FileWriter.
  • Create a FileWriter with the desired filename.
  • Pass your String to the write method.
  • Call the close method.


  • "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Saving to a txt file
     
    Similar Threads
    How the insertAtBack sets the next for head?
    Linked List help
    Linked List Sorting Problem
    Linked List Operations adding node after intervals.
    Linked List Sorting Problems