Move a file from a non-SMB location to a SMB location in Java

444 Views Asked by At

How do you move a file from a local non-SMB folder to a SMB location in the server?

Below code doesn't work, but it's something like this what I am after. I am able to authenticate the smb location.

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);

I get this error:

java.lang.ClassCastException: jcifs.smb1.smb1.SmbFile cannot be cast to java.nio.file.Path
1

There are 1 best solutions below

0
user3924633 On

You may be using an outdated library. Look for maintained alternatives such as JFileServer or jNQ.