文件系统加:
InputStream in = new FileInputStream("config.properties");
Properties p = new Properties();
p.load(in);
类加载器方式:在classpath目录下
InputStream in = Main.class.getClassLoader().getResourceAsStream("test/resource/config.properties");
与类同级目录:
InputStream in = Main.class.getResourceAsStream("config.properties");
在类的下一级目录:
InputStream in = Main.class.getResourceAsStream("resource/config.properties");
指定加载资源配置文件的classes相对路径 :
InputStream in = Main.class.getResourceAsStream("/test/resource/config.properties");