java - Relative path for properties file -
i'm using properties file:
try { properties.load(new fileinputstream("filename.properties")); } catch (ioexception e) { }
where should place filename.properties
? don't want specify absolute path code has work in different platforms. tried place in same directory de class doesn't work. (sorry if it's stupid question)
maybe can path current class placed somehow?
be sure property file available compiled (.class) file , way
getclass().getresource("filename.properties") // url, openstream
or
getclass().getresourceasstream("filename.properties") // inputstream
example:
import java.net.url; public class sampleload { public static void main(string[] args) { final url resource = sampleload.class.getresource("sampleload.class"); system.out.println(resource); } }
this main retrieves own compiled version @ runtime:
file:/c:/_projects/toolbox/target/classes/org/game/toolbox/sampleload.class
Comments
Post a Comment