prosseek
prosseek

Reputation: 191129

Where is the property file saved in eclipse?

I have this code for saving and loading property files in eclipse. I created an eclipse application project.

    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();
    }

It works fine, but I couldn't find the smcho.properties file in my computer. When I set the file path to an absolute path, the file is stored and loaded from the path. Where is the property file is saved with property file name alone?

Upvotes: 0

Views: 3331

Answers (2)

prosseek
prosseek

Reputation: 191129

For Mac, when I execute the eclipse application project that contains the code, property file is stored in where the eclipse is installed.

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

And from Waleed's answer, it seems that the directory is regarded as the working directory when launching an eclipse application from eclipse.

Upvotes: 0

Waleed Almadanat
Waleed Almadanat

Reputation: 1037

The file will be stored into the Working Directory, this is the path that you run the Java application from. Now if you run it from Eclipse, the file will be saved into the project's folder.

To make things even clearer, lets say you exported your code sample into an executable jar file, and placed it on the following path '/Users/prosseek/Desktop' and using the terminal you cd into '/Users/prosseek' and run the app from there, the properties file will be created in '/Users/prosseek' then if you cd into '/Users/prosseek/Desktop' and run the application again, a new file will be created within the Desktop path which is now the new working directory.

Hope this helps.

Upvotes: 3

Related Questions