-1

I am new to GWT, I want to read a property file, which stores database host, port, username, password. I have placed a config.properties files in server package.

    Properties prop = new Properties();
    prop.load(new FileInputStream("DBConfig.properties"));
    string host = prop.getProperty("host");


property file...
host=127.0.0.1
port=3306
username=root
password=root

I used constants as well. That didn't work for me.

I would really appreciate another approach. Thanks in advance.

Ovi Faur
  • 518
  • 3
  • 19
  • Is this [post](http://stackoverflow.com/questions/22269623/retrieve-init-parameters-outside-servlet/22270264#22270264) not helpful for you in this case? – Braj Aug 06 '14 at 12:45

1 Answers1

0

In the description of your problem you state that you placed a config.properties file in the server package, but in the code you provided you are using DBConfig.properties. So first please make sure that the filename is correct. Second make sure that the file is in the same package as the class from which you provided the above code. Third instead of FileInputStream you could use

Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("DBConfig.properties"));
String host = properties.getProperty("host");
Ovi Faur
  • 518
  • 3
  • 19
  • prop.load(this.getClass().getResourceAsStream("DBConfig.properties")); this.getClass() gives an error, The method I have used is static. I have written that method in Servlet. input = DBConfig.class.getClassLoader().getResourceAsStream(filename); returns null. Plz guide... – Xerox Shah Aug 06 '14 at 17:19