public class PropertyRead {
public static String read(String name) {
return read(name,"/String.properties");
}
public static String read(String name,String path) {
String result = "";
InputStream in = null;
Properties props = new Properties();
in = new PropertyRead().getClass().getResourceAsStream(path);
try {
props.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
}
}
}
//输出属性文件中的信息
Set set = props.keySet();
Iterator it = set.iterator();
try {
while (it.hasNext()) {
String key = (String) it.next();
if (key.equals(name)) {
result = new String(props.getProperty(key).getBytes("ISO-8859-1"),"utf-8");
}
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}