在本地写好的mapreduce程序想要连接远程服务器进行执行, 但在执行时: 连接远程服务器时出现一下异常:java.net.UnknownHostException: unknown host: master
I'm trying to copy a file from a local directory to a network
on a windows box. I'm using jcifs 1.3.17. I successfully get a connection to the destination, actually create the file there, get a "canWrite" status of "true", but when I try to copy the contents of the local file to the remote file, I get the following error:
jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: ..__MSBROWSE__.<01>
at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:317)
. . .
code snippet:
SmbFile source = new SmbFile(original);
SmbFile dest = new SmbFile (target,auth);
dest.createNewFile();
boolean canWrite = dest.canWrite();
source.copyTo(dest);
I don't get it... if I can create the file on the destination and smb sees that I can write to it, why does the doCopy fail?
java
smb
unknown-host
asked May 13 '15 at 14:20
scooter4j 13 5
|
1 Answers
1
解决方法
I don't get it too but... try this. It works!现象 在Mac上启动tomcat时,报了如下错误: Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.Unkn
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.
}
answered Jul 15 '15 at 10:16
iaforek 529 1 4 17 2 I would replace try-finally with try with resource. –
rkosegi Jul 15 '15 at 10:19 @rkosegi You are right. Use try-with-resource when you are using Java 1.7. My solution is for 1.6. –
iaforek Jul 15 '15 at 12:21
|
錯誤日志: jcifs.smb.SmbException: NTLMv2 requires extended security (jcifs.smb.client.useExtendedSecurity must be true if jcifs.smb.lmCompatibility >=



