拆分字符and读取properties文件

时间:2021-05-04 03:50:34
在方法里面建立properties对象
Properties pps = new Properties();
调用.load()方法
pps.load(new FileInputStream("E:\\workplace\\testStudent\\src\\we.properties"));
整个方法
     public static String getValueByKey(String key){
 
Properties pps = new Properties();
try {
pps.load(new FileInputStream("E:\\workplace\\testStudent\\src\\we.properties"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (String)pps.get(key);
 
建立main方法测试
 
public static void main(String[] args) {
int a=0;
 
String category=Constant.getValueByKey("UIConfig.category");
String[] categoryvalue = category.split("\\|");
for (String str : categoryvalue) {
String[] test = str.split("\\:");
System.out.println(test[1]);
System.out.println(test[0]);
}
 
 
 
}