有的功能需要打印日志文件,但是日志文件太多不方便查看,我就把信息输出到一个TXT文件中了。
下面就是我将要说的,往文件中写数据(增量),代码很简单,也可以放在你的代码中运行一下:
/** 往文件中写数据(增量)*/public static void writeFileData(){String words = "这是我需要插入的数据";FileWriter fileData = null;try {// 如果文件存在,则追加内容;如果文件不存在,则创建文件File file = new File("d:/download/logfile.txt");fileData = new FileWriter(file, true);} catch (IOException e) {e.printStackTrace();}PrintWriter pw = new PrintWriter(fileData);pw.println(words);pw.flush();pw.close();fileData=null;}