Relying on the filesystem like that for a webapp (i.e., using absolute paths) is not good practice will make your code less portable.
You should keep your files in a resources
directory and use the ClassLoader
to load your files relative to the classpath. See ClassLoader.getResource()
and ClassLoader.getResourceAsStream()
. Another option is to use ServletContext.getResource() or ServletContext.getResourceAsStream(). You can get the ServletContext
in servlets by using the inherited getServletContext()
method.