我想用来从我的Web应用程序的外面读取属性文件.我在windows环境中的tomcat中部署了一个war文件,我可以使用以下代码从我的Web应用程序外部读取属性文件.
//(Method 1.)
String filePath =
new java.io.File( ".").getCanonicalPath()+"/webapps/strsproperties/strs.properties";
// or
//(Method 2.)
String filePath = new File(System.getProperty("catalina.base"))+ "/webapps/strsproperties/strs.properties";
InputStream inputStream = null;
inputStream = new FileInputStream(filePath);
properties.load(inputStream);
String application = properties.getProperty("applications");
Run Code Online (Sandbox Code Playgroud)
在上面两种情况下,我都可以在windows中读取filePath.
问题是我无法使用第一种方法(相对路径)进程在Linux中读取filePath.
有没有办法在Linux env中使用tomcat中的相对路径读取文件?