IO stream 10 --- copy buffer flow (byte) to achieve non-text files --- technical Porter (still Silicon Valley)

  • Byte stream buffer, BufferedOutputStream default buffer size is 8192 bytes byte, full automatic flush ()
@Test
public void test6(){
    File srcFile = new File("FLAMING MOUNTAIN.JPG");
    File destFile = new File("FLAMING MOUNTAIN2.JPG");
    FileInputStream fis = null;
    FileOutputStream fos = null;

    try {
        //节点流
        fis = new FileInputStream(srcFile);
        fos = new FileOutputStream(destFile);
        //缓冲流
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        //复制文件
        byte[] buffer = new byte[10];
        int len;
        while ((len = bis.read(buffer)) != -1){
            bos.write(buffer, 0, len);
        }
    The catch} (IOException E) { 
        e.printStackTrace (); 
    } the finally { 
        // off the outer flow, the inner closed automatically 
        IF (BOS = null!) { 
            The try { 
                bos.close (); 
            } the catch (IOException E) { 
                e.printStackTrace (); 
            } 
        } 
        IF (BIS = null!) { 
            the try { 
                bis.close (); 
            } the catch (IOException E) { 
                e.printStackTrace (); 
            } 
        } 
    } 
}

  

Guess you like

Origin www.cnblogs.com/noyouth/p/11699339.html