BufferedWrite的用法

import java.io.*;

public class TestBufferedWrite {
	public static void main(String[] args) throws Exception {

		FileWriter fw = new FileWriter("f:/Test/Test.txt");

		BufferedWriter bw = new BufferedWriter(fw);
		bw.write("大家好,");
		bw.write("我是一个苦逼程序员-_-");
		// 建立新行
		bw.newLine();
		bw.write("我正在努力的写代码!");
		// 清空缓冲区
		bw.flush();
		// 关闭流
		bw.close();
		// 关闭流
		fw.close();

		FileReader fr = new FileReader("f:/Test/Test.txt");
		BufferedReader br = new BufferedReader(fr);

		String line;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}

		br.close();
		fr.close();
	}
}

你可能感兴趣的:(java)