Java File write text to file
import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; public class Main { public static void main(String[] argv) { saveString2File(new File("Main.txt"), "test from demo2s.com"); }/*from w ww . ja va 2 s. c om*/ public static final boolean saveString2File(File file, String content) { try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); bw.write(content); bw.close(); return true; } catch (Exception e) { return false; } } }