I am working on a dynamic web project in Eclipse with Tomcat 7. All of my html, css and javascript files are inside the WebContent folder in the eclipse workspace. All the java files are inside the src folder. All works well for simple programs. But now I want to read a text file from the java programs. I am not sure where to put the text file in the eclipse workspace so that it is correctly deployed to the Tomcat webapps directory inside ./metadata folder of eclipse.
Asked
Active
Viewed 4,632 times
2 Answers
0
You can use the ServletContext.getResourceAsStream() API.
An example can be found at this link . It suggests that the file should be kept in the /WEB-INF directory

Riju Mahna
- 6,718
- 12
- 52
- 91
-
i want to use the file in a separate class which i will call from the servlet – Saprativa Bhattacharjee Mar 19 '13 at 13:55
-
`URL url = this.getClass().getResource( "/stop.txt" );` returns null although my `stop.txt` file is present in WEB-INF folder – Saprativa Bhattacharjee Mar 19 '13 at 14:01
-1
put ur files inside webroot folder or outside webroot folder any where it is possible to read files .
inside classes folder is good because of default classpath for webapplication

ravula's
- 62
- 1
- 6
-
-
directely give ur filename ,suppose hi.txt isthere in clasees folder then "hi.txt" u r relative for inside classes folder. – ravula's Mar 19 '13 at 12:29
-