these properties keep driving me crazy. I’m reading everywhere, that even loading the properties should be no problem by just using:
Properties p = new Properties();
p.load(new FileInputStream("filename.properties");
Though in my case it doest work. Java is not finding the file, which is located in the class directory! Thats why i HAD TO use it with the Assetmanager:
String defaultProfileProperties = "filename.properties";
Resources resources = this.getResources();
AssetManager assetManager = resources.getAssets();
final Properties properties = new Properties();
try {
InputStream inputStream = assetManager.open(defaultProfileProperties);
properties.load(inputStream);
} catch (IOException e) {
System.err.println("Failed to open " + defaultProfileProperties + " property file");
e.printStackTrace();
}
Putting the filename.properties in the assets-folder.
Well, now I simply can’t save the properties-file by using .store(out,comment) …
I tried using a FileOutputStream with the path set to either “filename.properties”, or “assets/filename.properties”. Neither of them worked. I even added a slash here and there, but nothing is helping! I’m not finding any tutorials on the web, nor ppl having the same problem!
Could you please just help me? I guess this is such a simple thing, but i’m not getting a clue how to … blah
If you open a file with FileInputStream, then the starting directory (relative path) is based on the working directory when you started java, NOT the classpath. Opening a file with resources will reference the classpath entries.
Have you tried using a full path when using FileInputStream()? Try that and see if it works, and if it does, then you’ll need to either set the working directory at start up and/or reference your file via relative path from the start directory.