Search code examples
javafile-iorelative-pathfileinputstream

FileNotFoundException coming from Java web application


I am working on the web application with Eclipse. I have created one property file for database configuration. (DBProperty.properties) Please find below screen-shot of the folder structure.

enter image description here

I want to access this property file. I am accessing with below code.

FileInputStream input = new FileInputStream("src/resources/DBProperty.properties");

I have also tried many relative paths but not able to succeed.

I have set build path for this project.


Solution

  • You need to use

    MyClass.class.getClassLoader().getResourceAsStream("DBProperty.properties")