【Java/File】写添加到文本文件的函数
代码:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
....
/** * 写添加到文本文件 * @param filename * @param line */ public static void append2File(String filename,String line){ PrintWriter out; try { out = new PrintWriter(new FileOutputStream(new File(filename),true)); out.println(line); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
END