/**
* @author 林延涛
* @param filePath properties文件地址
* @param key properties中的key
* @return String
*/
public String readValue(String filePath,String key) {
Properties props = new Properties();
try {
InputStream in = this.getClass().getResourceAsStream(filePath);
props.load(in);
String value =new String(props.getProperty(key).getBytes("ISO-8859-1"),"UTF-8");
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
InitialLise il=new InitialLise();
System.out.println(il.readValue("/config/softicloud/generic/upload/uploadConfig.properties","userName"));
}
本文提供了一个使用Java读取Properties文件的示例代码。该方法接收文件路径和键名作为参数,并返回对应的值。通过将文件编码从ISO-8859-1转为UTF-8来正确解析字符。
5975

被折叠的 条评论
为什么被折叠?



