1.src 下相对路径
public CommonEmailUtil(){
Properties props = new Properties();
try {
File file=new File("H:\\DESKTOP\\email.properties");
props.load(this.getClass().getClassLoader().getResourceAsStream(file.getName()));
email_host = props.getProperty("email.host");
email_port = props.getProperty("email.port");
System.out.println(email_host+"++"+email_port);
} catch (IOException e) {
System.out.println("读取配置文件出错,请检查src下是否存在email.properties文件");
e.printStackTrace();
}
}
2.任何磁盘下绝对路径
public CommonEmailUtil(){
Properties props = new Properties();
try {
props.load(this.getClass().getClassLoader().getResourceAsStream("email.properties"));
email_host = props.getProperty("email.host");
email_port = props.getProperty("email.port");
System.out.println(email_host+"++"+email_port);
} catch (IOException e) {
System.out.println("读取配置文件出错,请检查src下是否存在email.properties文件");
e.printStackTrace();
}
}