I am trying to read a properties file from a package within my program without having to copy it to the plugin directory. I can read from a properties file which is in the plugin directory:
private String displayProperties()
{
Properties props = new Properties();
InputStream is = null;
try
{
File f = new File(getDataFolder()+"/test.properties");
is = new FileInputStream(f);
props.load(is);
return props.getProperty("Test1");
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
This is all good and works BUT the user is able to edit the properties file. I have done some 'googling' and what i have found is people saying its not possible to write to a properties file in the .jar file. I am not trying to write to it, I just want to read from it.
Is this possible? and if so how can I change my code to accomplish this?
(If you know of a tutorial that would be great too)
Edit: I have now solved the problem, all I had to do was to change the input stream from file to this:
is = getClass().getResourceAsStream("test.properties");
Now it works perfectly.