【发布时间】:2022-12-28 17:18:46
【问题描述】:
如何将文件从本地非 SMB 文件夹移动到服务器中的 SMB 位置?
下面的代码不起作用,但这就是我所追求的。我能够验证 smb 位置。
String sourceFile="target/abc.xml";
String smbDestinationFile="sharePath/abc/smblocation/xyz.xml";
SmbFile sTargetFile = performAuthenticationAndChecks(destinationFile, domain, domainUsername,
domainPassword);
Files.move(Paths.get(sourceFile), (Path) sTargetFile);
我收到此错误:
java.lang.ClassCastException: jcifs.smb1.smb1.SmbFile cannot be cast to java.nio.file.Path
【问题讨论】:
-
“不起作用”请解释(例如,显示异常)作为对您帖子的更新。
-
@JeffHolt 异常更新了问题
-
Paths.get(sTargetFile.getCanonicalPath())可能代替(Path) sTargetFile工作。 -
您可能确实遇到了 samba 问题,但您眼前的问题与 samba 根本无关。这只是一个数据类型问题。问题的标题不正确。
-
我不认为这是一个 samba 问题,因为我能够在 SMB 位置授权和删除文件而没有任何问题。当我尝试使用 getCanonicalPath() 时,我得到类似这样的信息:- java.nio.file.InvalidPathException: Illegal char <:> at index 4: smb1://sharePath/abc/smblocation/xyz.xml。请注意 smb 之后异常中出现的 '1'。实际路径是这样的 - smb://sharePath/abc/smblocation/xyz.xml。