I am working in Java 11.0.11 with Amazon Corretto. This code is running in a beanshell file as part of an identity governance system.
I am trying to use java.nio methods with Windows network paths.
I am able to create the path object using any method (path.of, Paths.get, File.toPath(), FileSystem.getPath, etc) and a sun.nio.fs.WindowsPath object is always returned.
Then when I try to use the WindowsPath object with any java.nio methods I get the error: methodName(sun.nio.fs.WindowsPath) not found in class'java.nio.etc.etc
This happens with Files.exists(path), Files.createDirectory(path), Files.getOwner(path), etc, etc
I am failing to find related results in searching and I am even having issues when I go as far as to use the FileSystems.getDefault().getPath() as well as sun.nio.fs.WindowsFileSystem getPath and sun.nio.fs.WindowsPath toWindowsPath which all respond the same way. It can reach the method but there is no version of the method that supports an argument of type sun.nio.fs.WindowsPath.
If I fall back to java.io methods everything works fine but I am intending on supporting symbolicLinks which are much easier in nio not to mention the better error handling so I'd prefer if I can get this working with nio.
Is there any preexisting packages that handle managing windows network folders already?
Alternatively, if I can't find a solution to get this working natively in java my plan is to just write a powershell script that will do the heavy lifting but I'm facing more then a little bit of sunk cost fallacy with the logic I already fleshed out in java.
import lava.lang.*;
import java.nio.*;
import java.io.*;
String Folder = "//idg-bridge/C$/TEMP/HomeDriveTest/testusername";
Path fnew = Path.of(Folder,new String[0]);
if(!Files.exists(fnew, LinkOption.NOFOLLOW_LINKS))
{
Files.createDirectory(fnew);
}
This fails at Files.exists(fnew, LinkOption.NOFOLLOW_LINKS) with exception:
Error in method invocation: Static method exists( sun.nio.fs.WindowsPath, java.nio.file.LinkOption ) not found in class'java.nio.file.Files'
If I use java.io (new File("//idg-bridge/C$/TEMP/HomeDriveTest/testusername")).exists() it makes it past the exists check without issue and then fails in exactly the same way at Files.createDirectory(fnew) with exception:
Error in method invocation: Static method createDirectory( sun.nio.fs.WindowsPath ) not found in class'java.nio.file.Files'