I mentioned last night that I was attempting to use property files. So let’s say you have a class in a jar file that reads a property file and the property file is in the jar. Is there any way to load the property file without knowing exactly on the file system where the property file lives? Should I be using a ResourceBundle instead?
The classloader has methods for this purpose. So, from a class that is in the same JAR as the property file (or really, if you’re not using multiple classloaders, any class) you can do this:
Properties props = new Properties();
InputStream propFileStream = this.getClass().getClassLoader().getResourceAsStream(“com/cephas/myprops.properties”);
props.load(propFileStream);
How to add comments in between each pair , while writing to a property file in java.