• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Saving to a txt file

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Keep in mind this is a really bad way of doing it, but for your simple example it's probably sufficient.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
  •  
    ice is for people that are not already cool. Chill with this tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic