java io

数据拷贝
     public static void copyFile(File sourceFile,File targetFile) throws IOException{
        BufferedInputStream inBuff=null;
        BufferedOutputStream outBuff=null;
        try{
            //缓冲输入流
            inBuff=new BufferedInputStream(new FileInputStream(sourceFile));
            //缓冲输出流
            outBuff=new BufferedOutputStream(new FileOutputStream(targetFile));
            
            byte[] b=new byte[1024*5];
            int len;
            while ((len=inBuff.read(b))!=-1) {
                outBuff.write(b,0,len);
            }
        }
        finally{
            if(inBuff!=null){
                inBuff.close();
            }
            if(outBuff!=null){
                outBuff.close();
            }
        }
    }

posted on 2012-05-23 17:44  雨渐渐  阅读(309)  评论(0编辑  收藏  举报

导航