java.net.UnknownHostException: ..__MSBROWSE__ 使用 jcifs 时
java.net.UnknownHostException: ..__MSBROWSE__ when using jcifs
我正在尝试将文件从本地目录复制到 windows 框上的网络共享。我正在使用 jcifs 1.3.17。我成功地连接到目的地,实际上在那里创建了文件,获得 "canWrite" 状态 "true",但是当我尝试将本地文件的内容复制到远程文件时,我得到了以下错误:
jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: ..__MSBROWSE__.<01>
at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:317)
。
.
.
代码片段:
SmbFile source = new SmbFile(original);
SmbFile dest = new SmbFile (target,auth);
dest.createNewFile();
boolean canWrite = dest.canWrite();
source.copyTo(dest);
我不明白...如果我可以在目的地创建文件并且 smb 看到我可以写入它,为什么 doCopy 会失败?
我也不太明白但是...试试这个。有效!
String source = "smb://SERVER/PATH/FILE";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "USERNAME", "PASSWORD");
SmbFile sourceFile = new SmbFile(source, auth);
String destination = "LOCAL_PATH_TO_FILE";
byte[] buffer;
int length;
try {
FileOutputStream fileOutputStream = new FileOutputStream(destination);
InputStream fileInputStream = sourceFile.getInputStream();
try {
buffer = new byte[16 * 1024 * 1024];
while ((length = fileInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}
} finally {
fileInputStream.close();
fileOutputStream.close();
}
} catch (SmbException e) {
// Error handling.
} catch (FileNotFoundException e) {
// Error handling.
} catch (IOException e) {
// Error handling.
}
致谢此问答:How to copy file from smb share to local drive using jcifs in Java?
我正在尝试将文件从本地目录复制到 windows 框上的网络共享。我正在使用 jcifs 1.3.17。我成功地连接到目的地,实际上在那里创建了文件,获得 "canWrite" 状态 "true",但是当我尝试将本地文件的内容复制到远程文件时,我得到了以下错误:
jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: ..__MSBROWSE__.<01>
at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:317)
。 . .
代码片段:
SmbFile source = new SmbFile(original);
SmbFile dest = new SmbFile (target,auth);
dest.createNewFile();
boolean canWrite = dest.canWrite();
source.copyTo(dest);
我不明白...如果我可以在目的地创建文件并且 smb 看到我可以写入它,为什么 doCopy 会失败?
我也不太明白但是...试试这个。有效!
String source = "smb://SERVER/PATH/FILE";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "USERNAME", "PASSWORD");
SmbFile sourceFile = new SmbFile(source, auth);
String destination = "LOCAL_PATH_TO_FILE";
byte[] buffer;
int length;
try {
FileOutputStream fileOutputStream = new FileOutputStream(destination);
InputStream fileInputStream = sourceFile.getInputStream();
try {
buffer = new byte[16 * 1024 * 1024];
while ((length = fileInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}
} finally {
fileInputStream.close();
fileOutputStream.close();
}
} catch (SmbException e) {
// Error handling.
} catch (FileNotFoundException e) {
// Error handling.
} catch (IOException e) {
// Error handling.
}
致谢此问答:How to copy file from smb share to local drive using jcifs in Java?