1.采用ClassLoader方式读取
private Properties load1() throws Exception{
properties = new Properties();
properties.load(Class.class.getResource("/ftp.properties").openStream());
return properties;
}
2.采用PropertiesLoaderUtils方式读取
private Properties load() {
properties = new Properties();
try {
properties = PropertiesLoaderUtils.loadAllProperties("ftp.properties");
} catch (IOException e) {
e.printStackTrace();
}
return properties;
}
3.采用getResourceAsStream
private Properties load2() throws Exception{
properties = new Properties();
properties.load(
DailySupportUtils.class.getResourceAsStream("/ftp.properties"));
return properties;
}
4.通过ResourceBundle资源包读取(配置文件在resource包中,配置文件不用加后缀名)
private List<String> load4() throws Exception {
List<String> list = new ArrayList<>();
ResourceBundle rb = ResourceBundle.getBundle("ftp");
Enumeration<String> keys = rb.getKeys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
String value = rb.getString(key);
list.add(value);
}
return list;
}