Reading a file from the executable JAR file itself using ClassLoader.getResourceAsStream(...) is a known concept to me, but how would I do the same using Java NIO?
The target is to have a function as follows:
static String readFullyFromJar(String filename) {
final Path path = Paths.get(Main.class.getResource(fileName).toURI());
final byte[] bytes = Files.readAllBytes(path);
return new String(bytes, CHARSET_ASCII);
}
While this works fine in the IDE, I get a
java.nio.file.FileSystemNotFoundException
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171))
when I try this with the real JAR, even though the target file is in the correct place.