I need to know where should I put a file in web application so that I could read it from servlet.
up until now, I have placed a folder named conf/config.cfg in the following structure
BankConfig/
WEB-INF/
libs/
classes/
conf/
config.cfg
and I’m reading it from a servlet like the following:
String fileName = "conf/config.cfg";
InputStream is;
try {
is =// getClass().getResourceAsStream(fileName);
new FileInputStream(fileName);
prop.load(is);
}catch(Exception e){}
If you want to read it from the servlet, I would use
ServletContextto read the file and properties.Example:
Note: The
fileNamestarts with a/(root from servlet context perspective). The only thing is I would have put theconf/config.cfginside theWEB-INFfolder (as it’s hidden from view by the Servlet container, and do the same as above, instead I’ll change the file name as: