Home > DeveloperSection > Forums > How can I save a String in a text file using Java?
Ankit Singh

Total Post:341

Posted on    October-04-2013 9:18 AM

 Java Java 

 1 Reply(s)
 883  View(s)
Rate this:

How can I save a string in a text file?

jacob rasel
jacob rasel

Total Post:88

Posted on    October-04-2013 9:30 AM

If you're simply outputting text, rather than any binary data, the following will work:

PrintWriter out = new PrintWriter("filename.txt");

Then, write your String to it, just like you would to any output stream:


You'll need exception handling, as ever. Be sure to call out.close() when you've finished writing.

Edit: further simplified per Jonik's comments.

Modified On Mar-15-2016 05:50:22 AM

Don't want to miss updates? Please click the below button!

Follow MindStick