java淺說(3) 複製檔案

2021-07-23 08:53:24 字數 912 閱讀 9697

* 需求:把e:\\123.mp4複製到當前專案目錄下的copy.mp4中

* * 位元組流四種方式複製檔案:

* 基本位元組流一次讀寫乙個位元組:

共耗時:117235毫秒

* 基本位元組流一次讀寫乙個位元組陣列: 共耗時:156毫秒

* 高效位元組流一次讀寫乙個位元組: 共耗時:1141毫秒

* 高效位元組流一次讀寫乙個位元組陣列: 共耗時:47毫秒

*/public class copymp4demo

// 高效位元組流一次讀寫乙個位元組陣列:

public static void method4(string srcstring, string deststring)

throws ioexception

bos.close();

bis.close();

}// 高效位元組流一次讀寫乙個位元組:

public static void method3(string srcstring, string deststring)

throws ioexception

bos.close();

bis.close();

}// 基本位元組流一次讀寫乙個位元組陣列

public static void method2(string srcstring, string deststring)

throws ioexception

fos.close();

fis.close();

}// 基本位元組流一次讀寫乙個位元組

public static void method1(string srcstring, string deststring)

throws ioexception

fos.close();

fis.close();}}

java複製檔案工具類

public int copy string source name,string dest name,int type throws ioexception if source filefile.canread if dest filefile.exists else else else if p...

Java 複製檔案最快方法

不考慮多執行緒優化,單執行緒檔案複製最快的方法是 檔案越大該方法越有優勢,一般比常用方法快30 private static void niotransfercopy file source,file target catch ioexception e finally 如果需要監測複製進度,可以用...

java實現資料夾的複製和檔案的複製

複製到特定目錄下 public void copyfiles file rootfile,file copyfile 因為是複製所以,要保證複製後的資料夾和原資料夾的名字包括裡面的子資料夾,子檔案名字都保持一致 string rootpath rootfile.getabsolutepath sub...