1.未使用缓冲
public static void method4() {
try {
Writer writer = new FileWriter(new File("D:\\var\\demo.txt"));
for (int k=0; k<10; k++)
writer.write('a');
writer.close();
System.out.println("结束");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2.使用缓冲
public static void method5() {
try {
Writer writer = new BufferedWriter(new FileWriter(new File("D:\\var\\demo.txt")));
for (int k=0; k<10; k++)
writer.write('a');
writer.close();
System.out.println("结束");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
3.缓冲API
public BufferedWriter(Writer out) // 缓冲默认8K
public BufferedWriter(Writer out, int sz) // 自定义缓冲区