Scriptim Scriptim - 22 days ago 19
Java Question

Cannot execute jar file - NoSuchFileException

When I run this jar file, I get following RuntimeException:


Exception in thread "main" java.nio.file.NoSuchFileException:
src\NumberConverterLog.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 de.scriptim.NumberConverter.main(NumberConverter.java:30)

Answer

You'll need to change how you access resources in a jar to a stream.

this.getClass().getResourceAsStream("/file.txt");
Comments