字节缓冲输出流:
package InstreamPack;import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;public class BufferStreamDemo01 {public static void main(String[] args) throws IOException {
// FileOutputStream fos = new FileOutputStream("D:\\JavaDemo\\java.txt");
//
// BufferedOutputStream bos = new BufferedOutputStream();BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\JavaDemo\\java01.txt"));bos.write("hello\r\n".getBytes());bos.write("world\r\n".getBytes());bos.close();}
}
字节缓冲输入流:
package InstreamPack;import java.io.*;
import java.nio.Buffer;
import java.nio.charset.StandardCharsets;public class BufferStreamDemo01 {public static void main(String[] args) throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\JavaDemo\\java01.txt"));int by;while((by=bis.read())!=-1){System.out.print((char)by);}bis.close();}
}
package InstreamPack;import java.io.*;
import java.nio.Buffer;
import java.nio.charset.StandardCharsets;public class BufferStreamDemo01 {public static void main(String[] args) throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\JavaDemo\\java01.txt"));byte[] bys = new byte[1024];int len;while((len=bis.read(bys))!=-1){System.out.print(new String(bys,0,len));}bis.close();}
}