java properties读取第一对key-value

2024年12月01日 13:43
有1个网友回答
网友(1):

参数是propeties文件路径!
//读取properties的全部信息
public static Vector readProperties(String filePath) {
Properties props = new Properties();
Property property=new Property();
Vector propVector=new Vector();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
//在这里遍历
while (en.hasMoreElements()) {
String key = en.nextElement().toString();//key值
String Property = new String(props.getProperty(key).getBytes("ISO-8859-1"),"gb2312");//value值
propVector.add(key);
}
return propVector;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}