JAVA複製檔案最快的演算法

2021-09-06 17:42:16 字數 1020 閱讀 4130

/**

* 複製檔案

* * @param srcfile

* 原始檔file

* @param destdir

* 目標目錄file

* @param newfilename

* 新檔名

* @return 實際複製的位元組數,如果檔案、目錄不存在、檔案為null或者發生io異常,返回-1

*/public static long copyfile1(file srcfile, file destdir, string newfilename) else if (!destdir.exists()) else if (newfilename == null) else

bout.flush();

bin.close();

bout.close();

copysizes = i;

} catch (filenotfoundexception e) catch (ioexception e)

}return copysizes;

}/**

* 複製檔案(以超快的速度複製檔案)

* * @param srcfile

* 原始檔file

* @param destdir

* 目標目錄file

* @param newfilename

* 新檔名

* @return 實際複製的位元組數,如果檔案、目錄不存在、檔案為null或者發生io異常,返回-1

*/public static long copyfile2(file srcfile, file destdir, string newfilename) else if (!destdir.exists()) else if (newfilename == null) else catch (filenotfoundexception e) catch (ioexception e)

}return copysizes;

}

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...

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...