Properties properties = new Properties();
//第一种
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(“xxx.properties”));
Thread.currentThread().getContextClassLoader().getResourceAsStream(“xxx.properties”);
//第二种
InputStream input = ClassLoader.getSystemResourceAsStream(“xxx.properties”);
BufferedReader bf = new BufferedReader(new InputStreamReader(input, “UTF-8”));
properties.load(bf);
//第三种
String path = System.getProperty(“sp.home”, test1.class.getResource("/").getFile());
properties.load(new FileInputStream(new File(path + “/config/warningServer.properties”)));
目前用到的加载配置文件的方法
最新推荐文章于 2024-07-27 23:50:11 发布
本文介绍了在Java中加载配置文件的三种常见方法:通过线程上下文类加载器、系统类加载器以及结合系统属性和文件路径。这些方法在读取应用程序的配置参数时非常实用。
2765

被折叠的 条评论
为什么被折叠?



