If it is placed in the webapp's classpath, then just use:
1 |
InputStream input = servletContext.getResourceAsStream("file.txt"); |
If it is placed in the global classpath, then use:
1 |
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("file.txt"); |
If it is placed in the webcontent, then just use:
1 |
InputStream input = new FileInputStream(servletContext.getRealPath("file.txt")); |
The examples assumes that they're placed in the root. You can of course use relative path as opposed to the classpath root or webcontent root, e.g. path/to/file.txt
. You can get the ServletContext
in Struts by ServletActionContext#getServletContext()
.