JAVA追加写入文本文件

	public void method1() {
		FileWriter fw = null;
		try {
			//如果文件存在,则追加内容;如果文件不存在,则创建文件
			File f=new File("E:\\dd.txt");
			fw = new FileWriter(f, true);
		} catch (IOException e) {
			e.printStackTrace();
		}
			PrintWriter pw = new PrintWriter(fw);
			pw.println("追加内容");
			pw.flush();
		try {
			fw.flush();
			pw.close();
			fw.close();
		} catch (IOException e) {
		e.printStackTrace();
		}
	}

 

posted @ 2019-02-24 20:56  麦克斯-侯  阅读(449)  评论(0编辑  收藏  举报
百纵科技