public String readProperties(String name){
Properties props = new Properties();;
InputStream in = null;
InputStreamReader re =null;
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mail.properties");//可以读取src下以及src同级目录下的properties文件(
与src同级的目录和src一样 都是虚拟目录
)
re = new InputStreamReader(in,"UTF-8");
props.load(re);
} catch (IOException e) {
e.printStackTrace();
}finally{
if(re != null){
try {
re.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String nameString=(String) props.get(name);
System.out.println(nameString);
return nameString;
}