Skip to content

Instantly share code, notes, and snippets.

@francisnnumbi
Created August 5, 2017 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisnnumbi/ce7b8a31f82a2b4c38dde4ebb0d2f12f to your computer and use it in GitHub Desktop.
Save francisnnumbi/ce7b8a31f82a2b4c38dde4ebb0d2f12f to your computer and use it in GitHub Desktop.
Did you know that you can save plain text to file using Formatter.class? You need to import java.util package. You'll use format() method for that and specify the format expression to be of type String - "%s".
public void saveText(File file, String content){
try{
Formatter out = new Formatter(file);
out.format("%s", content);
out.close();
}catch(IOException ioe){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment