public class EmailSender{
private static boolean sendEmail=true;
static {
InputStream is = EmailSender.class.getClassLoader().getResourceAsStream("email.properties");
Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
sendEmail=properties.containsKey("sendEmail")?Boolean.valueOf((String)properties.get("sendEmail")):true;
}
}
配置文件名 : email.properties
里面的属性和值 : sendEmail=true