public class PropertiesUtil { private static Properties properties; private static String url; private static String FILE_NAME = "application.properties"; static{ try{ properties = new Properties(); InputStream fis = PropertiesUtil.class.getClassLoader().getResourceAsStream(FILE_NAME); properties.load(fis); url = PropertiesUtil.class.getClassLoader().getResource(FILE_NAME).toURI().toURL().toString(); }catch (Exception e){ e.printStackTrace(); } } /** * 读取属性 * @param key * @return */ public static String getProperties(String key) { return properties.getProperty(key); } /** * 设置属性 * @param key * @param value */ public static void setProperties(String key ,String value)throws IOException { OutputStream out = new FileOutputStream(url); properties.setProperty(key, value); properties.store(out,"key:" + key); } }
读取properties文件的工具类
最新推荐文章于 2023-02-05 18:49:15 发布