我读了关于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();
答案 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);