方法一
Properties properties = new Properties()
InputStream stream = PropertiesUtil.class.getClassLoader().getResourceAsStream("setting.properties")
properties.load(stream)
方法二
public static URL getResource(String fileName, ClassLoader loader)
throws IOException {
URL resource = loader.getResource(fileName);
if (resource == null) {
throw new IOException("找不到resource: " + fileName);
}
return resource;
}
public static Properties getProperties(URL source) throws IOException {
InputStream input = source.openStream();
try {
Properties p = new Properties();
p.load(input);
return p;
} finally {
input.close();
}
}