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; } }
  • 相关阅读:
    python学习笔记(33)pycharm中使用git
    VUE基础3-过滤器与生命周期
    VUE基础2-双向数据绑定
    VUE基础1方法与指令
    HTML基础之JS
    HTML基础之DOM操作
    HTML基础之CSS
    HTML基础之HTML标签
    python学习笔记(32)多线程&多进程
    python学习笔记(30)深拷贝、浅拷贝
  • 原文地址:https://www.cnblogs.com/lshan/p/10283471.html
Copyright © 2011-2022 走看看