Java property 的加载读取

xiaoxiao2021-02-28  110

方法一

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(); } }
转载请注明原文地址: https://www.6miu.com/read-34374.html

最新回复(0)