Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to read decrypted property file.

File location is /WEB-INF/classes/db.properties

Decoder java file is src/a2.util/Decoder.java

which has method called readFile(String fileName).

When I call the method like this:

Decoder.readFile("db.properties")

I got file not found exception. saying..

db.properties (System cannot find specified file)

Can someone help me with this ?

share|improve this question

marked as duplicate by BalusC java Nov 17 at 7:53

This question was marked as an exact duplicate of an existing question.

1  
Resources are not files, and /WEB-INF/classes is not the current working directory when your servlet executes. – EJP Nov 17 at 7:15

You can not access as above.

You can get real path as:

ServletContext context = this.getServlet().getServletContext();     
String fullPath = context.getRealPath("/WEB-INF/classes/db.properties");

OR

java.net.URL url = [ClassName].class.getClassLoader().getResource("/WEB-INF/classes/db.properties"); 

Unless try with this as:

InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/classes/db.properties");

OR

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("/db.properties");
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.