Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from file in Eclipse plugin

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

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

I get a file not found exception. Is there a better way of doing this?

like image 614
user1688404 Avatar asked Jan 29 '13 14:01

user1688404


1 Answers

Did you remember to include it in the build?

Secondly, using the classloader resource is probably better anyway

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

Also, there is another way of opening a resource URL in eclipse using

url = new URL("platform:/plugin/com.example.plugin/config.properties");
InputStream inputStream = url.openConnection().getInputStream();
like image 163
Niels Bech Nielsen Avatar answered Oct 02 '22 01:10

Niels Bech Nielsen