N
N
Nikolay Baranenko2016-07-28 10:38:21
Java
Nikolay Baranenko, 2016-07-28 10:38:21

Where should the file for getClassLoader().getResourceAsStream be located?

Hello.

There was a need to transfer information about database connections to a separate file. I tried to use this option, BUT I still can’t figure out where the db.properties file should be physically located

Properties prop = new Properties();
                InputStream inputStream = FetchData.class.getClassLoader().getResourceAsStream("/db.properties");
                prop.load(inputStream);
                String driver = prop.getProperty("driver");
                String url = prop.getProperty("url");
                String user = prop.getProperty("user");
                String password = prop.getProperty("password");


Tried to place /web-inf/classes/db.properties does not find it.
Tried to specify an absolute path - the result is also negative.

Where should he be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-07-28
@zolt85

You'd better use the construct
in this case the starting point would be "WEB-INF/classes"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question