字符流缓冲区和字节流缓冲区底层运行差异不大
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class IoDemo {
public static void main(String[] args) throws IOException {
methord1();
methord2();
}
private static void methord2() throws IOException {
// TODO Auto-generated method stub
BufferedWriter b = new BufferedWriter(new FileWriter("e:/lishuai.txt"));
b.write("lishuai");
//newLine方法是换行的作用。
b.newLine();
b.write("shuai");
b.newLine();
b.flush();
b.close();
}
private static void methord1() throws IOException {
// TODO Auto-generated method stub
BufferedReader b = new BufferedReader(new FileReader("e:/lishuai.txt"));
String ch = null;
while ((ch = b.readLine()) != null) {
System.out.println(ch);
}
b.close();
}
}