java - How to set right path of property file? -
i have problem can't resolve. need read properties file, can't set right path. documentation of java.io.file saying have set in src/... doesnt work, did path current file , have same problem.
exception : filenotfound
propertyreader class:
public final class propertyreader { private properties prop = new properties(); private inputstream input = null; public properties getproperties(file file) { try { input = new fileinputstream(file); // load properties file prop.load(input); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } { if (null != input) { try { input.close(); } catch (ioexception e) { e.printstacktrace(); } } } return prop; } }
and applicationcontroller.class uses propertyreader:
@requestmapping(value = "/result", method = requestmethod.get) public string resultpage(modelmap model) { //getting property key "path" model.addattribute("path", new propertyreader().getproperties(file).getproperty("path")); return "result";
if i'm setting path c://.. works fine.
thank , have nice day!
try use following example read property file.
import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.util.properties; public class app { public static void main(string[] args) { properties prop = new properties(); inputstream input = null; try { input = new fileinputstream("config.properties"); // load properties file prop.load(input); // property value , print out system.out.println(prop.getproperty("mysqldb")); system.out.println(prop.getproperty("dbuser")); system.out.println(prop.getproperty("dbpassword")); } catch (ioexception ex) { ex.printstacktrace(); } { if (input != null) { try { input.close(); } catch (ioexception e) { e.printstacktrace(); } } } } }
its depends on framework using springmvc, jsf , struts. these framework have own shortcut ways access property files.
Comments
Post a Comment