首页 新闻 会员 周边

Java拷贝文件

0
悬赏园豆:5 [已解决问题] 解决于 2012-08-18 17:25

请问如何用Java编写程序拷贝一个文件, 尽量使用效率高的方式.

Baolon的主页 Baolon | 初学一级 | 园豆:175
提问于:2012-08-17 20:03
< >
分享
最佳答案
0
import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class CopyFile {
    
    public static void main(String[] args) throws IOException {
        String srcFilePath = "D:/data.csv";//要拷贝的文件路径
        String destFilePath = "E:/data.csv";//拷贝后的存放路径
        copyFile(srcFilePath,destFilePath);
    }
    
    /**
     * copy file from srcFilePath to destFilePath
     * @param srcFilePath        源文件路径
     * @param destFilePath    目标文件路径
     * @throws IOException 
     */
    public static void copyFile(String srcFilePath,String destFilePath) throws IOException {
        File srcFile=new File(srcFilePath);  
        File destFile=new File(destFilePath);  
        FileUtils.copyFile(srcFile, destFile);
    }
}
收获园豆:5
CN.programmer.Luxh | 菜鸟二级 |园豆:362 | 2012-08-17 22:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册