【发布时间】:2015-06-27 02:33:30
【问题描述】:
我在以下代码中收到此错误(请注意,这不会发生在我的本地计算机上,仅发生在我的构建服务器上):
Files.readAllBytes(Paths.get(getClass().getResource("/elasticsearch/segmentsIndex.json").toURI()), Charset.defaultCharset());
还有例外:
Caused by: java.nio.file.FileSystemNotFoundException: null
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)
at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
at java.nio.file.Paths.get(Paths.java:143)
我试图通过关注solution 来修复它;我的代码现在看起来像这样:
URI segmentsIndexURI = getClass().getResource("/elasticsearch/segmentsIndex.json").toURI();
Map<String, String> env = new HashMap<>();
env.put("create", "true");
FileSystem zipfs = FileSystems.newFileSystem(segmentsIndexURI, env); //exception here
Path segmentsIndexPath = Paths.get(segmentsIndexURI);
我收到以下异常:
java.lang.IllegalArgumentException: Path component should be '/'
at sun.nio.fs.UnixFileSystemProvider.checkUri(UnixFileSystemProvider.java:77)
at sun.nio.fs.UnixFileSystemProvider.newFileSystem(UnixFileSystemProvider.java:86)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:326)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)
似乎没有任何效果。 我应该如何构建文件的路径?
【问题讨论】:
-
您是否注意到有问题的异常标题与帖子中的异常不同?请澄清。
-
您将 file 的 URI 作为新的 file system 传递?我不知道这有什么意义。
-
请注意,描述中提到的异常是我在遵循解决方案后得到的异常。第一个代码 sn-p 是在标题中引发异常的代码...如果您愿意,我也可以包含原始异常
-
您是否打开了您的 jar 或目录部署以查看您的文件是否存在?在正确的地方?
-
在我的本地机器上运行良好,所以我认为这与环境有关,否则路径在本地运行时将无法作为 wlel 运行