Java 找不到 .property 文件 Ubuntu

标签 java ubuntu properties io filenotfoundexception

我有一个加载 .properties 文件的游戏。该文件的名称是 properties.properties。当我在 Windows 中运行游戏时,它可以运行,但是当我在 Linux (Ubuntu) 中加载它时,它会抛出 fileNotFoundException。正在运行的 .jar 和属性文件在同一个文件夹中,我使用以下方式调用属性文件:

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

甚至尝试过:

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

连同

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

我不确定为什么它不起作用,但是当我运行它时: java -jar ~/Desktop/Files/bin/NPS.jar 在 Linux 终端中,我得到错误:

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)

我不知道为什么!这有点令人沮丧....因为它在 Windows 中工作得很好。

最佳答案

代替 java -jar ~/Desktop/Files/bin/NPS.jar 试试 cd ~/Desktop/Files/bin/&& java -jar NPS.jar

关于Java 找不到 .property 文件 Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15694776/

相关文章:

ubuntu - chef-jira Recipe - 未找到 Recipe apache2

laravel - 无法 Composer 转储自动加载 - 文件放置内容错误?

c# - 使属性 getter 和 setter 相等(自动属性初始化程序)

java - 在 Web 应用程序中找不到属性文件的路径?

java - 在程序处理时 setText()

java - openAccessory 的返回值到底是多少?

java - 关于构造函数

java - 如何在java中使用紧凑字节将对象序列化为字节数组

ubuntu - 远程连接时如何让 Cloud9 退出只读模式?

javascript - 为什么这个可配置属性不可删除?