public class ReadProperties {
public static Properties getPro() {
Properties property = new Properties();
try {
property.load(ReadProperties.class.getClassLoader()
.getResourceAsStream("mailProperty.properties"));//properties文件名
} catch (IOException e) {
e.printStackTrace();
}
return property;
}
public static void main(String [] args){
Properties property = ReadProperties.getPro();
String mailServerHost = property.getProperty("MailServerHost");
String mailServerPort = property.getProperty("MailServerPort");
System.out.println(mailServerHost);
System.out.println(mailServerPort);
}
}
mailProperty.properties文件:
# This file contains my default Mail properties.
MailServerHost = smtp.163.com
MailServerPort = 25