import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; /** * @author */ public class TextUtils { public static void appendToFile(String content, File file) throws IOException { TextUtils.appendToFile(content, file, System.getProperty("file.encoding")); } public static void appendToFile(String content, File file, String encoding) throws IOException { BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), encoding)); writer.write(content); } finally { if (writer != null) writer.close(); } } public static void saveToFile(String content, File file) throws IOException { TextUtils.saveToFile(content, file, System.getProperty("file.encoding")); } public static void saveToFile(String content, File file, String encoding) throws IOException { BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), encoding)); writer.write(content); } finally { if (writer != null) writer.close(); } } }