0

I am creating a Javafx application in Intelij and FileInputStream works perfectly. However, when I create a .jar file from the project and try to run it the code fails to run as it is unable to locate the file in the file input stream. Here is my code:

ObjectInputStream os = new ObjectInputStream(new FileInputStream("src/settingStorage.bin"));

Am I doing something wrong?

joshLor
  • 1,034
  • 1
  • 12
  • 27

2 Answers2

0

There is always some issue accessing a file outside a jar, depending on where the file location is. You can check this SO question/answer to have an idea on accessing your file.

Read properties file outside JAR file

johnII
  • 1,423
  • 1
  • 14
  • 20
0

Try this:

EDIT: Look at this again, I left part out.

ObjectInputStream os = new ObjectInputStream(new FileInputStream(SomeClass.class.getResourceAsStream(“settingStorage.bin")));

This usually works for me. When I run this, it operates fine, in AND out of the development area. Don’t include /src, as when you call getResourceAsStream off a class, it already checks inside the jar.

Cheers!

Jacob B.
  • 423
  • 3
  • 12