我使用以下JCIFS代码将文件从本地磁盘复制到共享驱动器
public boolean copyFiles(String srcFilePath, String destinationFileName) throws Exception {
boolean successful = false;
SmbFileOutputStream sfos = null;
try {
String user = USER_NAME + ":" + PASSWORD;
System.out.println("User: " + user);
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("mydomain",USER_NAME,PASSWORD);
Config.setProperty("resolveOrder", "DNS");
String destinationFilePath = NETWORK_FOLDER +"/" +destinationFileName;
SmbFile sFile = new SmbFile(destinationFilePath, auth);
sfos = new SmbFileOutputStream(sFile);
// sfos.write(getBytesFromFile(new File(srcFilePath))); -- 1st approach
// Files.copy(new File(srcFilePath).toPath(),sfos); -- 2nd approach
FileInputStream fis = new FileInputStream(srcFilePath);
BufferedReader brl = new BufferedReader(new InputStreamReader(fis));
String b = null;
while ((b = brl.readLine()) != null) {
sfos.write(b.getBytes());
}
sfos.flush();
successful = true;
System.out.println("Successful" + successful);
} catch (Exception e) {
successful = false;
e.printStackTrace();
} finally {
if (sfos != null) {
sfos.close();
}
}
return successful;
}
复制10 MB文件需要10多分钟。而当我直接复制相同的文件时,它需要大约1分钟。我尝试了3种方法来复制文件(参见代码的注释部分),但没有一种显示出任何显着差异。
无论如何我可以提高JCIFS的性能吗?
答案 0 :(得分:0)
作为一种解决方法,我已经安装了共享驱动器并将文件复制到该驱动器中。