属性文件在eclipse中保存在哪里?

时间:2012-12-18 17:12:04

标签: java eclipse properties

我有这个代码用于在eclipse中保存和加载属性文件。我创建了一个eclipse应用程序项目。

    Properties properties = new Properties();
    try {
        String propertyFilePath = "smcho.properties";
        // properties.load(new FileInputStream(propertyFilePath));
        properties.setProperty("database", "values");
        properties.store(new FileOutputStream(propertyFilePath), null);

        // Now, re-read the property file
        properties.load(new FileInputStream(propertyFilePath));
        System.out.println(properties.getProperty("database"));
    } catch (IOException e) {
        e.printStackTrace();
    }

它工作正常,但我在计算机中找不到smcho.properties文件。 当我将文件路径设置为绝对路径时,将从路径存储和加载文件。属性文件在哪里保存,只有属性文件名?

2 个答案:

答案 0 :(得分:3)

该文件将存储到工作目录中,这是您运行Java应用程序的路径。现在,如果从Eclipse运行它,该文件将保存到项目的文件夹中。

为了使事情变得更加清晰,我们假设您将代码示例导出到可执行的jar文件中,并将其放在以下路径'/ Users / prosseek / Desktop'中,然后使用终端进入'/ Users / prosseek'并从那里运行应用程序,属性文件将在'/ Users / prosseek'中创建,然后如果你进入'/ Users / prosseek / Desktop'并再次运行应用程序,将在桌面路径中创建一个新文件,现在是新的工作目录。

希望这有帮助。

答案 1 :(得分:0)

对于Mac,当我执行包含代码的eclipse应用程序项目时,属性文件存储在安装eclipse的位置。

./Applications/eclipse_rcp_juno/Eclipse.app/Contents/MacOS/smcho.properties

从Waleed的回答来看,当从eclipse启动eclipse应用程序时,该目录似乎被视为工作目录。