java - Unable to get properties from properties file? -
java - Unable to get properties from properties file? -
i have written class fetchprop extends class propmap fetches values properties file.when run fetchprop junit test case giving me right output i.e fetches properties way want.then have created class createreport calls method of fetchprop helps in generation of report.but when run test case on createreport fetchprop not fetching properties used when run standalone?
can 1 suggest may issue
ps: have checked path properties file placed , displaying properties file path every time run programme , file has properties want get.
it might depend on how fetch properties file. if using like:
private properties readprops() throws filenotfoundexception, ioexception { file f = new file("c:\\path\\to\\file\\props.properties"); properties props = new properties(); props.load(new fileinputstream(f)); homecoming props; }
...then might work in unit tests not when running application. might want seek like:
private properties readprops2() throws ioexception { inputstream stream = this.getclass().getresourceasstream("props.properties"); properties props = new properties(); props.load(stream); homecoming props; }
...which reads file classpath instead.
java
Comments
Post a Comment