zoukankan      html  css  js  c++  java
  • PropertiesUtils

    Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("properties/statusMapping.properties")); //path   springboot --> resource/properties/statusMapping.properties



    package
    com.icil.elsa.subscribe.milestone.common.utils; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Properties; /** * ************************************************************************* * <PRE> * @ClassName: : PropertiesUtils * * @Description: : * * @Creation Date : 17 Jan 2019 5:28:06 PM * * @Author : Sea * * * </PRE> ************************************************************************** */ public class PropertiesUtils { /** * * @param path * @param key * @return */ public static String getProperty(String path, String key) { Properties properties = new Properties(); String value = ""; try { synchronized (properties) { InputStream in = new BufferedInputStream(new FileInputStream(path)); properties.load(in); } value = (String) properties.get(key); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return value; } /** * * @param path * @param key * @param value */ public static void updateProperty(String path, String key, String value) { Properties properties = new Properties(); //String profilepath = PropertiesUtils.class.getResource("/").getPath() + path;//nosonar try { InputStream in = new BufferedInputStream(new FileInputStream(path)); properties.load(in); OutputStream fos = new FileOutputStream(path); properties.setProperty(key, value); properties.store(fos, "Update value"); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); } } public static Properties getProperties(String path) { Properties properties = new Properties(); try { synchronized (properties) { InputStream in = new BufferedInputStream(new FileInputStream(path)); properties.load(in); } } catch (IOException e) { return null; } return properties; } /** * * @param path * @param key * @return */ public static String getPropertiesOnServer(String path, String key) { Properties properties = new Properties(); String value = ""; try { InputStream in = new BufferedInputStream(new FileInputStream(path)); properties.load(in); value = (String) properties.get(key); } catch (IOException e) { e.printStackTrace(); } return value; } }
  • 相关阅读:
    Goahead在linux环境下安装部署
    vim卡住怎么办
    Clickhouse 实现 row number功能
    JavaScript ES6 模块化
    MySQL012事务的四个基本特征是什么
    MySQL015简述mysql中索引类型有哪些,以及对数据库的性能的影响
    MySQL010MySQL执行计划怎么看
    JavaScript ES6 Promise
    MySQL011如何处理MySQL的慢查询
    MySQL009MySQL为什么需要主从复制和读写分离
  • 原文地址:https://www.cnblogs.com/lshan/p/10283471.html
Copyright © 2011-2022 走看看