好的這就是我所做的
在java中使用robocopy命令在兩個位置之間複製目錄。測試了一個〜9GB的文件,並能夠在〜9分鐘內複製。以下是代碼片段
String sourceFolder = new File("C:\\test\\robocopytest\\source\\20170925T213857460").toString();
String destFolder = new File("C:\\test\\robocopytest\\destination\\20170925T213857460").toString();
StringBuffer rbCmd = new StringBuffer();
if ((sourceFolder != null) && (destFolder != null))
{
if (sourceFolder.contains(" ")) {
if (sourceFolder.startsWith("\\")) {
sourceFolder = "/\"" + sourceFolder.substring(1) + "/\"";
} else {
sourceFolder = "\"" + sourceFolder + "\"";
}
}
if (destFolder.contains(" ")) {
if (destFolder.startsWith("\\")) {
destFolder = "/\"" + destFolder.substring(1) + "/\"";
} else {
destFolder = "\"" + destFolder + "\"";
}
}
rbCmd.append("robocopy " + sourceFolder + " " + destFolder);
Process p = Runtime.getRuntime().exec(rbCmd.toString());
}
當您說「共享」時,是否暗示目標目錄位於網絡共享上? –
@Ian,是的,它在網絡共享 –
更具體,它是一個NAS(網絡附加存儲) –