返回值为空,读不到配置文件
public static String read(String fileName,String key) {
FileInputStream inputFile = null;
String filePath = null;
Properties pro = new Properties();
try {
filePath = new String(URLDecoder.decode(PropertyUtil.class
.getClassLoader().getResource(fileName).getPath(),
"UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("-----------"+filePath);
try {
String value = "";
inputFile = new FileInputStream(filePath);
pro.load(inputFile);
inputFile.close();
if(pro.contains(key)){
value = pro.getProperty(key);
return value;
}else{
return "";
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return "";
} catch (IOException e) {
e.printStackTrace();
return "";
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
求大虾们帮忙看看那。。。