简介
缓冲流就是对原始流进行包装,以提高原始数据流读写数据的性能
缓冲流继承体系
缓冲流的作用
构造器API
代码示例
try(// 创建字节输入流和输出流InputStream is = new FileInputStream("test.txt");OutputStream os = new FileOutputStream("test4.txt");// 使用缓冲流进行包装BufferedInputStream bis = new BufferedInputStream(is);BufferedOutputStream bos = new BufferedOutputStream(os);){// 读取数据byte[] bytes = new byte[1024];int len = -1;while ((len = bis.read(bytes)) != -1) {// 写入数据bos.write(bytes, 0, len);}// 刷新缓冲区bos.flush();} catch (Exception e) {e.printStackTrace();}