读取配制文件的时候,使用下面的方法,可方便获取classpath绝对路径:
Thread.currentThread().getContextClassLoader().getResource("").getPath();
Thread.currentThread().getContextClassLoader().getResource("").getPath();
propertie = new Properties();
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
try {
inputFile = new FileInputStream(path + XXX.properties);
propertie.load(inputFile);
inputFile.close();
} catch (FileNotFoundException ex) {
System.out.println("文件不存在");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println("装载文件失败");
ex.printStackTrace();
}