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());
            }
        }
    }
}
posted @ 2013-01-31 14:06  陈晓明  阅读(272)  评论(0编辑  收藏  举报