FileNotFoundException, although the file is in place and the path is correct

I am trying to solve a problem that seems very strange to me. I looked at least five similar topics here on StackOverflow, and none of them gave an answer. But to the problem itself: I want to read in the file when the application starts. When I run the application in the IDE (IntelliJ Idea), everything is fine. Although, when I create it using Gradle, Java throws a FileNotFoundException:

java.io.FileNotFoundException: file:/home/user/IdeaProjects/time-keeper/build/libs/time-keeper-0.7-beta.jar!/data.csv (No such file or directory)

The file path is correct, the file exists, the jar has the appropriate permissions. Announcement:

File dataFile = new File(ClassLoader.getSystemResource("data.csv").getFile());
Handle<TimeTask> dataHandle = new FileHandle(dataFile);
+4
source share
1 answer

As long data.csvas the file itself, everything works. This is probably true if you run the application from your development environment. In this case

ClassLoader.getSystemResource("data.csv").getFile()

. , gradle JAR, data.csv,

/home/user/IdeaProjects/time-keeper/build/libs/time-keeper-0.7-beta.jar!/data.csv

(data.csv JAR), . java.io.File URL- . data.csv File, .

"", getSystemResourceAsStream, ( , "real" ) InputStream.

+10

All Articles