1

I have a game that loads a .properties file. the name of the file is properties.properties. when i run the game in windows, it works, but when i load it in Linux (Ubuntu) it throws the fileNotFoundException. the running .jar and property file are in the same folder, and i'm calling the property file using:

currentProp = new Properties();
    try {
        currentProp
                .load(new FileInputStream(
                        "../bin/properties.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }

and have even tried:

currentProp = new Properties();
    try {
        currentProp
                .load(new FileInputStream(
                        "properties.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }

along with

currentProp = new Properties();
    try {
        currentProp
                .load(new FileInputStream(
                        "../properties.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }

i'm not exactly sure why it isnt working, but when i run it with: java -jar ~/Desktop/Files/bin/NPS.jar in the Linux terminal, i get the error:

java.io.FileNotFoundException: ../bin/properties.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at main.Start.loadProperties(Start.java:56)
at main.Start.main(Start.java:34)
    Exception in thread "main" java.lang.NullPointerException
at main.Start.main(Start.java:36)

and i have no clue as to why! it is mildly frustrating.... because it works just fine in windows.

0

1 Answer 1

4

instead of java -jar ~/Desktop/Files/bin/NPS.jar try cd ~/Desktop/Files/bin/ && java -jar NPS.jar

Sign up to request clarification or add additional context in comments.

4 Comments

also, since that worked, how come i cannot right click it, and select run as Oracle Java 7 and have it work? because if i do that with my other jar, it works just fine....
On unix based platform, the CWD (current working directory) is the one you are currently in and it is passed to JVM. On Windows, you have probable navigated to the bin folder (cwd is the bin folder).
You may find out what CWD was used in-code by: System.getProperty("user.dir")
Quite common practice on unix based platforms is to store the property files in ~/.yourapp/properties.properties. Then you can access this path by System.getProperty("user.home") + File.separator + ".yourapp" + File.separator + "properties.properties"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.