字符流緩沖區(qū)和字節(jié)流緩沖區(qū)底層運(yùn)行差異不大
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();
}
}