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.

project structure

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -