Properties prop = new Properties();
String path = AlarmController.class.getResource("/").getPath(); //AlarmController在哪个类里面写的就写哪个类
System.out.println(path); ///D:/workspace/cxfvp/src/main/webapp/WEB-INF/classes/ property放在这里
String websiteURL = (path+ "area.properties"); //得到自己的文件位置
try{
//读取属性文件area.properties
InputStream in = new BufferedInputStream (new FileInputStream(websiteURL));
prop.load(in); ///加载属性列表
String jinhua = prop.getProperty("jinhua"); //取value
String hangzhou = prop.getProperty("hangzhou");
String ningbo = prop.getProperty("ningbo");
System.out.println(jinhua);
}
catch(Exception e){
System.out.println(e);
}
配置文件