Reading from a properties file in an Eclipse plugin

I need to read configuration details from a properties file in eclipse. I set config.properties at the same level as plugin.xml and in the class file that I call:

 Properties properties = new Properties(); FileInputStream file; String path = "./config.properties"; file = new FileInputStream(path); properties.load(file); 

I get file not found exception . Is there a better way to do this?

+4
source share
2 answers

You did not forget to include it in the assembly?

Secondly, using a class loader resource is probably better anyway

 InputStream fileStream = myClass.getResourceAsStream( "/config.properties" ); 

In addition, there is another way to open a resource URL in eclipse using

 url = new URL("platform:/plugin/com.example.plugin/config.properties"); InputStream inputStream = url.openConnection().getInputStream(); 
+3
source

Put the properties file at the root of your project. This should be where the user.dir system property is user.dir . The FileInputStream constructor is in this directory for the file.

You can confirm that it is in the correct directory by displaying a system property.

 System.getProperty("user.dir"); 
0
source

All Articles