My code use getClass().getResource() to get the file location but when I create the jar file it can't find my file even I copy the to jar file directory.
And the log give me a weird path Server2018.jar!\com\company\party.txt
It has the "!" after the jar file name.
java.io.FileNotFoundException: file:\C:\Users\baram\IdeaProjects\Server2018\out\artifacts\Server2018_jar\Server2018.jar!\com\company\party.txt (The filename, directory name, or volume label syntax is incorrect)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(Unknown Source)
at java.base/java.io.FileInputStream.<init>(Unknown Source)
at java.base/java.io.FileReader.<init>(Unknown Source)
at com.company.FileManager.getVote(FileManager.java:285)
at com.company.PieParty.createScene(PieParty.java:74)
at com.company.PieParty.initFx(PieParty.java:58)
at com.company.PieParty.access$100(PieParty.java:21)
at com.company.PieParty$1.run(PieParty.java:48)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
This is what I use. Is there a better way to done this?
URL pty = getClass().getResource("party.txt");
File file = new File(pty.getPath());
reader = new BufferedReader(new FileReader(file));
Scanner sc = new Scanner(reader);