提问人:Chris 提问时间:8/18/2023 最后编辑:Jorn VerneeChris 更新时间:8/18/2023 访问量:88
静态方法存在( sun.nio.fs.WindowsPath, java.nio.file.LinkOption ) 在类中找不到 java.nio.file.files'
Static method exists( sun.nio.fs.WindowsPath, java.nio.file.LinkOption ) not found in class'java.nio.file.Files'
问:
我正在使用 Amazon Corretto 使用 Java 11.0.11。 此代码作为身份治理系统的一部分在 beanshell 文件中运行。
我正在尝试将java.nio方法与Windows网络路径一起使用。
我可以使用任何方法(path.of、Paths.get、File.toPath()、FileSystem.getPath 等)创建路径对象,并且始终返回一个 sun.nio.fs.WindowsPath 对象。
然后,当我尝试将 WindowsPath 对象与任何 java.nio 方法一起使用时,我收到错误:methodName(sun.nio.fs.WindowsPath) not found in class'java.nio。等等。等
Files.exists(path)、Files.createDirectory(path)、Files.getOwner(path) 等都会发生这种情况
我在搜索中找不到相关结果,甚至在使用 FileSystems.getDefault().getPath() 以及 sun.nio.fs.WindowsFileSystem getPath 和 sun.nio.fs.WindowsPath toWindowsPath 时都遇到了问题,它们都以相同的方式响应。它可以访问该方法,但没有支持 sun.nio.fs.WindowsPath 类型的参数的方法版本。
如果我回退到 java.io 方法,一切正常,但我打算支持symbolicLinks,这在nio中要容易得多,更不用说更好的错误处理了,所以我更希望我能把它与nio一起工作。
是否有任何预先存在的包已经处理管理 Windows 网络文件夹?
或者,如果我找不到一个解决方案来让它在 java 中原生工作,我的计划是只编写一个 powershell 脚本来完成繁重的工作,但我面临着更多的沉没成本谬误,我已经在 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);
}
这在 Files.exists(fnew, LinkOption.NOFOLLOW_LINKS) 处失败,并出现异常:
Error in method invocation: Static method exists( sun.nio.fs.WindowsPath, java.nio.file.LinkOption ) not found in class'java.nio.file.Files'
如果我使用 java.io (new File(“//idg-bridge/C$/TEMP/HomeDriveTest/testusername”)).exists(),它会毫无问题地通过存在检查,然后在 Files.createDirectory(fnew) 以完全相同的方式失败,并出现异常:
Error in method invocation: Static method createDirectory( sun.nio.fs.WindowsPath ) not found in class'java.nio.file.Files'
答: 暂无答案
评论
Path fnew = …
Path
WindowsPath fnew = (WindowsPath) Path.of(Folder);
getClass()
Path.of
Path.of
Path fnew …