Forums Register Login

Saving to a txt file

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send


Keep in mind this is a really bad way of doing it, but for your simple example it's probably sufficient.
+Pie Number of slices to send: Send
 

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.
  • Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 2040 times.
    Similar Threads
    Linked List Sorting Problems
    Linked List help
    Linked List Operations adding node after intervals.
    Linked List Sorting Problem
    How the insertAtBack sets the next for head?
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 06:43:58.