HOW CAN I SAVE A STRING IN A TEXT FILE USING JAVA?

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
Java 
 954  View(s)
Ratings:
Rate this:

How can I save a string in a text file?

  1. jacob rasel

    Post:88

    Points:616
    Re: How can I save a String in a text file using Java?

    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:

    out.println(text);

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!