Tomcat default main directory:
getServletContext().getRealPath("/"); /var/lib/tomcat7/webapps/webapp1/
System.getProperty("catalina.base"); /var/lib/tomcat7
Load config file
Properties pp = new Properties();
InputStream fis = getServletContext().getResourceAsStream("WEB-INF/settings.properties");
pp.load(fis);
Read File
String filePath = this.getServletContext().getRealPath("abc.text"); FileReader fileReader = new FileReader(filePath); BufferedReader bufferedReader = new BufferedReader(fileReader); String line = bufferedReader.readLine(); //do with line bufferedReader.close(); fileReader.close();
No comments:
Post a Comment