1:获取文件所在的路径
String dir = System.getProperty("user.dir"); //获得tomcat所在的工作路径
System.out.println(dir);
//获取到存储了文件存储位置的filedir.properties 文件路径
String dir2 = dir.substring(0, dir.length()-4) + File.separator +"webapps" + File.separator + "项目名" +File.separator + "WEB-INF"
+ File.separator + "classes" + File.separator + "目录名" + File.separator + "目录名" + File.separator + "file.properties";
2:通过properties文件,获取到里面的filePath的值
/**
* 获取filePath路径【properities文件】中key对应的值,
* @param filePath properities文件路径【包含properities文件】
* @param key 要查找的key值
* @return key对应的value
*/
public String GetValueByKey(String filePath, String key) {
Properties pps = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
pps.load(in);
String value = pps.getProperty(key);
//System.out.println(key + " = " + value);
in.close();
return value;
}catch (IOException e) {
e.printStackTrace();
return null;
}
}