Accessing local filesystem on the server from a servlet

我的未来我决定 提交于 2019-12-25 05:28:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!