請問如何用Java編寫程序拷貝一個文件, 盡量使用效率高的方式.
Java拷貝文件
慕運維8079593
2018-12-07 02:36:42
TA貢獻1815條經(jīng)驗 獲得超13個贊
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); } }
舉報