有的功能需要打印日志文件,但是日志文件太多不方便查看,我就把信息输出到一个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;
	}

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2022-01-02
  • 2021-08-09
  • 2021-12-08
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
相关资源
相似解决方案