0

I am running Tomcat on a Unix server, how can I write a Servlet to read from files on the Unix server but not contained in the WebContent folder.

Rory Harrison
  • 117
  • 10
  • 1
    One approach is to define a system or environment variable(s) to point to the location of the file(s). This allows local/dev/test/prod to use different locations. [This](https://stackoverflow.com/questions/7054972/java-system-properties-and-environment-variables) might help. Another approach is to have a properties file, such as application.properties, which contains all of the properties that might be different between environments. Then just have a single system/environment variable which points to that properties file. – Andrew S Sep 07 '18 at 14:36
  • I have a path variable $file_name that points to the file, would this work? Would you know how to get the specific file back from System.getenv()? Thanks @AndrewS – Rory Harrison Sep 07 '18 at 14:42
  • 1
    Use $file_name in the shell script to define a system property: `java ... -Dfile_name=$file_name ...`. Then in the code: `String fileName = System.getProperty("file_name")`. – Andrew S Sep 07 '18 at 14:50

0 Answers0