BufferedInputStream() 该类实现缓冲流输出对象(可以向底层输出流写入字节而不必为写入的每一个字节导致底层系统的调用)
BufferedOutputStream() 创建BufferedOutputStream()将创建一个内部缓冲数组 当从流中读取或跳过字节时,内部缓冲区根据需要从所包含的输入流中重新填充,一次很多字节
构造方法
字节缓冲输出流BufferedOutputStream(OutputStream out)
字节缓冲输入流BufferedInputStream(InputStream in)
缓冲区仅仅提供缓冲,真正的读写数据还得依靠基本的字节流对象
package day2; import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class BufferedOutputStreamTest { public static void main(String[] args) throws IOException { FileOutputStream fos = new FileOutputStream("write.txt"); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write("hello\t\n".getBytes()); bos.write("world\t\n".getBytes()); bos.close(); fos.close(); } }
package day2; import java.io.*; public class BufferedOutputStreamTest { public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("write.txt"); BufferedInputStream bis = new BufferedInputStream(fis); int by; while ((by=bis.read())!=-1){ System.out.print((char)by); } bis.close(); fis.close(); } }