问题
I need to access an external directory (which contains some logs of a different application) from my servlet. From what I've seen all the file paths are resolved from the servlet context. How can I access files outside the servlet?
回答1:
You can provide a full path when opening a given file so you can just do that if supported by your servlet container (most do).
Note that accessing the underlying file system is making your application dependent on behavior not guaranteed to work by the servlet specification, so it may not work on all web containers - an example could be a server spread over two physical computers, any of which may execute a given request, as a File valid on one physical computer may not be valid on the other. This is probably not relevant in your case, but you need to know that going outside the spec make your program vendor dependent.
来源:https://stackoverflow.com/questions/16975416/accessing-local-filesystem-on-the-server-from-a-servlet