JAVA 缓冲流为何要配合字节数组的使用?
缓冲流是在缓冲区中创建了一个字节数组,缓冲区是在内存当中的,效率很高,它创建的这个字节数组是用来储存输出流等传递过来的数据的,直到储存到8196长度时
,它才会向外输出.而输出流向这个缓冲区传递数据时,如果是用字节数组进行的,那么效率就会更高
package test; import java.io.*; public class BufferInputDemo { public static void main(String[] args) throws IOException { System.out.println("========="); BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("./1.txt")); //写数据 BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("./3.txt")); int m; while ((m=bufferedInputStream.read() )!=-1){ System.out.println((char) m); bufferedOutputStream.write(m); } bufferedInputStream.close(); bufferedInputStream.close(); } }