开发者

How to read external file (which is outside of container folder ) in servlet?

开发者 https://www.devze.com 2023-02-14 18:56 出处:网络
how I can read a file in servlet which开发者_如何转开发 is outside of servlet container ?In my job i have used the system property values to read the properties file outside the servlet container or W

how I can read a file in servlet which开发者_如何转开发 is outside of servlet container ?


In my job i have used the system property values to read the properties file outside the servlet container or WEB-INF folder or outside application context.

If you are using JBOSS server then use the

System.getProperty("jboss.server.home.dir");

or for Tomcat

System.getProperty("catalina.home");

Along with the above code , use the System.getProperty("file.separator");

This way you can read the updated changes from the file and prevent redeployement of war or jar file and works in all platforms(windows,unix).

if you are running a standalone application, u can supply your own property like below during application launch

java -Dconfig.url="D:/Apps/"
String prop = System.getProperty("config.url");


In order to read a file outside the container, you will have to use the absolute physical path of the file. But there are issues with this approach. The file's path may differ from your development system and production system. You will also face issues with file access permissions.

It would be better to include your configuration files within your application's reach.

0

精彩评论

暂无评论...
验证码 换一张
取 消