@Test
public void testBufferInputStream(){
    BufferedInputStream bfis = null;
    try {
        bfis = new BufferedInputStream(new FileInputStream("demo005"));
        byte[] data = new byte[2048];
        int length=bfis.read(data);
        String str = new String(data,0,length);
        System.out.println(str);
        //就以上的用法,和之前使用的FileInputStream没有区别。
        //但是在Buffered内部中,他会一次读取很多的数据到缓冲区中,再从缓冲区读取。
        //不用再每次都和硬盘交互,节约通讯时间。
    } catch (IOException e) {
        e.printStackTrace();
    }finally{
        try {
            bfis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
                
            
        
                    
                
浙公网安备 33010602011771号