Java 使用JCIFS性能问题将文件从本地驱动器复制到共享驱动器
我使用以下JCIFS代码将文件从本地磁盘复制到共享驱动器Java 使用JCIFS性能问题将文件从本地驱动器复制到共享驱动器,java,jcifs,Java,Jcifs,我使用以下JCIFS代码将文件从本地磁盘复制到共享驱动器 public boolean copyFiles(String srcFilePath, String destinationFileName) throws Exception { boolean successful = false; SmbFileOutputStream sfos = null; try { String user = USER_NAME + ":" + PASSWORD;
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的性能吗?作为一种解决方法,我已安装共享驱动器并将文件复制到该驱动器中。同样的问题。有人知道加快文件传输的设置/解决方法吗?