When I run a jar file that accesses other files in the src
directory, I get the following RuntimeException
:
Exception in thread "main" java.nio.file.NoSuchFileException: src\FileToBeAccessed.txt.lck at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) at sun.nio.fs.WindowsFileSystemProvider.newFileChannel(Unknown Source) at java.nio.channels.FileChannel.open(Unknown Source) at java.nio.channels.FileChannel.open(Unknown Source) at java.util.logging.FileHandler.openFiles(Unknown Source) at java.util.logging.FileHandler.(Unknown Source) at Program.main(Program.java:30)
The code works fine when I run it directly without building a jar file.
You'll need to change how you access resources in a jar to a stream.
this.getClass().getResourceAsStream("/file.txt");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments