//1. new java.utils.properties
Properties p = new Properties();
//2. 读取文件test.properties
p.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"));
如果test文件里面内容是a=b /换行 c=d 这种格式
可以直接通过p.get("a")拿到值b
-----------------------------------遍历---------------------------------------
public static Map<String,String> getFileIO(String fileName){
Properties prop = new Properties();
Map<String,String> propMap=new HashMap<String, String>();
InputStream in = PropertiesUtil.class.getResourceAsStream(fileName);
try {
prop.load(in);
Set<Object> keyset = prop.keySet();
for (Object object : keyset) {
String propValue= prop.getProperty(object.toString()).toString();
propMap.put(object.toString(), prop.getProperty(object.toString()).toString());
System.out.println(object.toString()+" : "+propValue);
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}