使用jcifs时如何使用smb文件名获取完整路径

时间:2016-02-18 07:16:54

标签: java samba jcifs

我读了关于smbfile的jCIFS的api,但我还没有找到如何使用文件名获取完整的smb路径。 我希望它返回“smb://aaa.bbb.com/sharedFolder/picture.jpg” 而它返回“smb://aaa.bbb.com/picture.jpg” 有代码:

String user = "user";
String password = "password";
String sharedFolder = "sharedFolder/";
String path = "smb://aaa.bbb.com/";
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);
//String canonicalPath = smb.getCanonicalPath(); 
String filePath = smbFile.getUncPath();

1 个答案:

答案 0 :(得分:0)

您的代码中没有使用变量sharedFolder。你可以做到,

String path = "smb://aaa.bbb.com/sharedFolder";
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);

String sharedFolder = "sharedFolder/";
String path = "smb://aaa.bbb.com/" + sharedFolder; // <-- append it
String fileName = "picture.jpg";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", user, password);
SmbFile smb = new SmbFile(path, auth);
SmbFile smbFile = new SmbFile(smb, fileName);