BufferOutputStream :字节缓冲输出流
BufferInputStream :字节缓冲输入流
BufferedWriter :字符缓冲输出流
BufferedReader :字符缓冲输入流
public class BufferStreamDome {
public static void main(String[] args) throws IOException {
// method_01();
// method_02();
// method_03();
method_04();
}
// BufferOutputStream dome 字节缓冲输出流
public static void method_01() throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream("E:\\folder_io_dome\\c.txt");
BufferedOutputStream bos01 = new BufferedOutputStream(fileOutputStream);
bos01.write("反正没人看得见,我是大帅逼!!!我最屌".getBytes());
bos01.flush();
bos01.close();
}
// BufferInputStream dome 字节缓冲输入流
public static void method_02() throws IOException {
FileInputStream fileInputStream = new FileInputStream("E:\\folder_io_dome\\c.txt");
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
int len = 0;
byte[] chars = new byte[1024];
while ((len = bufferedInputStream.read(chars)) != -1){
System.out.println(new String(chars,0,len));
}
bufferedInputStream.close();
}
// BufferedWriter dome 字符缓冲输出流
public static void method_03() throws IOException{
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("E:\\folder_io_dome\\d.txt",true));
bufferedWriter.write("I am big shuaibi !!");
bufferedWriter.flush();
bufferedWriter.close();
}
// BufferedReader dome 字符缓冲输入流
public static void method_04() throws IOException{
BufferedReader bufferedReader = new BufferedReader(new FileReader("E:\\folder_io_dome\\d.txt"));
char[] chars_arr = new char[1024];
int Effective_len = 0 ;
while ((Effective_len = bufferedReader.read(chars_arr)) != -1){
System.out.println(new String(chars_arr, 0, Effective_len));
}
bufferedReader.close();
// BufferedReader readline
BufferedReader bufferedReader1 = new BufferedReader(new FileReader("E:\\folder_io_dome\\d.txt"));
String read_line = null;
do {
read_line = bufferedReader1.readLine();
System.out.println(read_line);
}while (read_line != null );
bufferedReader.close();
}
}