配置文件的路径为根路径:
//获取该配置文件的相对路径
String path = SysTemplate.class.getClassLoader().getResource("generator.properties").getPath();
File file = new File(path);
Properties pps = new Properties();
pps.load(new FileInputStream(file));
Enumeration enum1 = pps.propertyNames();//得到配置文件的名字
while(enum1.hasMoreElements()) {
String strKey = (String) enum1.nextElement();
String strValue = pps.getProperty(strKey);
System.out.println(strKey + "=" + strValue);
}
} catch (FileNotFoundException e) {
System.out.println("文件找不到異常");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}