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; } }
  • 相关阅读:
    一种flink 作业提交失败的情况描述与原因排查
    Linux中对管道命令中的任意子命令进行返回码校验
    优化算法与特征缩放
    优化算法
    mvn-dependencies-vs-dependencyManagement
    Caused by java.lang.Exception Failed to send data to Kafka Expiring
    学习ArrayList的扩容机制
    SpringBoot多数据源配置
    idea内存不足或过大闪退
    利用csv文件批量编辑更新sql
  • 原文地址:https://www.cnblogs.com/lshan/p/10283471.html
Copyright © 2011-2022 走看看