更新时间:2023-02-06 22:26:34
我注意到,jCIFS对读取的每个块都执行了操作"(afair jcifs.smb.SmbTransport.checkStatus(..)),即每个读入缓冲区的块.这意味着增加缓冲区的大小实际上可能会加快速度,尽管实际的问题仍然存在,但只会发生1到2次,对整体时间的影响较小.
设置"jcifs.util.loglevel = 3"并查看真正的错误是很有帮助的.
在我的情况下,我不得不最后设置"jcifs.smb.client.dfs.disabled = false",因为"jcifs.resolveOrder = DNS"无济于事..
I'm trying to copy a file from my local machine to Shared folder in a windows server. This is the function which I used.
public static void copyFileUsingJcifs(final String domain, final String userName, final String password, final String sourcePath, final String destinationPath) throws IOException {
final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, userName, password);
final SmbFile sFile = new SmbFile(destinationPath, auth);
final SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(sFile);
final FileInputStream fileInputStream = new FileInputStream(new File(
sourcePath));
final byte[] buf = new byte[16384];
int len;
while ((len = fileInputStream.read(buf)) > 0) {
smbFileOutputStream.write(buf, 0, len);
}
fileInputStream.close();
smbFileOutputStream.close();
}
I tried this answer, but didn't work for me. When I do normal copying(Copy and Paste) it only takes maximum of 8minutes for a 25MB file. But when I use my java program using this function its taking more than 20minutes. How can I make this copying faster? Thanks in advance.
What I noticed is that jCIFS does "something" (afair jcifs.smb.SmbTransport.checkStatus(..)) for every chunk it reads - i.e. for each chunk that is read into the buffer. That means increasing your buffer size might really speed things up, although the real problem still exists, but only occurs 1 or 2 times having a lower impact on the overall time..
It helps a lot to set "jcifs.util.loglevel=3" and have a look what's really wrong..
In my case I had to set "jcifs.smb.client.dfs.disabled=false" in the end, as "jcifs.resolveOrder=DNS" didn't help..