[Java]高效文件拷贝方式——批处理

2018-01-07  本文已影响0人  AGalen

如题,直接上源码

public static void copyFile(File srcFile,File destFile)throws Exception{
        if(!srcFile.exists()){
            throw new IllegalArgumentException("File:" + srcFile + "Not exists");
        }
        else if(!srcFile.isFile()){
            throw new IllegalArgumentException(srcFile + "Is Not File");
        }
        else{
            FileInputStream in = new FileInputStream(srcFile);
            FileOutputStream out = new FileOutputStream(destFile);
            byte []buf = new byte[8*1024];
            int b = 0;
            while((b = in.read(buf,0,buf.length)) != -1){
                out.write(buf,0,b);
                out.flush();
            }
            out.close();in.close();
        }
    } 
上一篇 下一篇

猜你喜欢

热点阅读