Java基础之IO流,通过字节流缓冲区进行媒体文件的复制操作

import java.io.*;

class BufferedCopyFileDemo
{
    public static void main(String[] args)throws IOException
    {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
    
        try
        {
            bis = new BufferedInputStream(new FileInputStream(new File("001.avi")));
            bos = new BufferedOutputStream(new FileOutputStream(new File("001-1.avi")));
            
            int ch = 0;
            while((ch=bis.read())!=-1)
            {
                bos.write(ch);
            }            
        }
        catch(IOException e)
        {
            System.err.println(e.getMessage());
        }
        finally
        {
            try            
            {
                if(null!=bis)bis.close();
                if(null!=bos)bos.close();
            }
            catch(IOException e)
            {
                System.err.println(e.getMessage());
            }
        }
    }
}
原文地址:https://www.cnblogs.com/cxmsky/p/2886936.html