NutzCN Logo
问答 Nutz Boot 打包后,resources 下的文件该如何获取
发布于 1044天前 作者 shevawen 1257 次浏览 复制 上一个帖子 下一个帖子
标签:

直接运行 main 函数,以下代码是可以执行的

URL res = getClass().getClassLoader().getResource(scriptPath);
try (Stream<String> stream = Files.lines(Paths.get(res.toURI()), StandardCharsets.UTF_8)) {
	stream.forEach(s -> contentBuilder.append(s).append("\n"));
} catch (IOException | URISyntaxException e) {
	hrow new Exception("script file missing.", e);
}

Nutz Boot 打包后就找不到文件了

java.nio.file.FileSystemNotFoundException
        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)

请问如何处理?

1 回复

直接url.openStream就能读取啦

添加回复
请先登陆
回到顶部