• 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; } }
  • 相关阅读:
    日志格式设计
    域!!!
    Sql Server 2000 中游标的使用示例
    微软下一代操作系统Windows 7仅占25MB空间!
    添加aspnet_isapi.dll的映射时“确定”按钮不可用的解决方案
    巧用Array对象来实现字符串的反转
    [有人帮我说明了原因,明天找人测试一下]紧急求助!!(请您帮看看我的一个在线考试系统的部分代码是否有问题啊?)
    给站长的一点建议
    用SQL SERVER中的的一函数实现表中数据记录随机排序
    使用内嵌资源
  • 原文地址:https://www.cnblogs.com/lshan/p/10283471.html
Copyright © 2020-2023  润新知