Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("properties/LazadaStatusMapping.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;
} }

PropertiesUtils的更多相关文章

  1. Property工具类,Properties文件工具类,PropertiesUtils工具类

    Property工具类,Properties文件工具类,PropertiesUtils工具类 >>>>>>>>>>>>>& ...

  2. PropertiesUtils(普遍做法)

    public class PropertiesUtil{ private static Properties properties; static{ InputStream in = null; tr ...

  3. iframe无刷新跨域并获得返回值

    参考:http://geeksun.iteye.com/blog/1070607 /** * iframe跨域提交大数据 * @param action 跨域地址 * @param arr [ {na ...

  4. Properties类使用

    package com.emolay.util; import java.io.IOException; import java.io.InputStream; import java.util.Pr ...

  5. Redis常用方法

    首先构建非切片连接池jedisPool对象,写好配置redis连接的方法. /** * 构建redis切片连接池 * * @param ip * @param port * @return Jedis ...

  6. 使用SparkSQL实现多线程分页查询并写入文件

    一.由于具有多张宽表且字段较多,每个宽表数据大概为4000万条,根据业务逻辑拼接别名,并每张宽表的固定字段进行left join 拼接SQL.这样就能根据每个宽表的主列,根据每个宽表的不同字段关联出一 ...

  7. Servlet & JSP - Java Web 访问资源的路径问题

    假设 Web 工程的目录结构如下图所示,并且 HelloServlet 配置为 @WebServlet(name = "helloServlet", urlPatterns = { ...

  8. Java获取.properties配置文件某一项value根据key值

    public static String getProperty(String key){ InputStream in = PropertiesUtils.class.getResourceAsSt ...

  9. jsp-2 简单的servlet连接mysql数据库 增删改查

    连接mysql数据库的操作 有增删改查 用的包有 commons-lang3-3.5 mysql-connector-java-5.1.40-bin 但是实际上也就是 数据查询和数据处理两种 所以对数 ...

随机推荐

  1. VUEX 学习

    语法   翻译  功能介绍 module(模块)extend(扩展)extract(提取)export(输出)router(路由器)components(组件) store(储存)state (声明. ...

  2. [蓝桥杯]ALGO-86.算法训练_矩阵乘法

    问题描述 输入两个矩阵,分别是m*s,s*n大小.输出两个矩阵相乘的结果. 输入格式 第一行,空格隔开的三个正整数m,s,n(均不超过200). 接下来m行,每行s个空格隔开的整数,表示矩阵A(i,j ...

  3. Ubuntu 14.10 下Spark on yarn安装

    1 服务器分布 服务器 说明 192.168.1.100 NameNode 192.168.1.101 DataNode 192.168.1.102 DataNode 2 软件环境 2.1 安装JDK ...

  4. flume http source示例讲解

    一.介绍 flume自带的Http Source可以通过Http Post接收事件. 场景:对于有些应用程序环境,它可能不能部署Flume SDK及其依赖项,或客户端代码倾向于通过HTTP而不是Flu ...

  5. 廖雪峰Java3异常处理-1错误处理-1Java的异常

    1.计算机运行中的错误 在计算机程序运行的过程中,错误总会出现,不可避免的 用户输入错误 读写文件错误 网络错误.内存耗尽.无法连接打印机不可 String s = "abc"; ...

  6. 多级字典表单的Python实现

    需求: 可依次选择进入各子菜单 可从任意一层往回退到上一层 可从任意一层退出程序 数据结构 menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'go ...

  7. [UE4]Child Widget中的事件调度器

    在Child Widget中新建事件调度器,就会自动在使用该Child Widget的父级界面的事件列表中自动自动出现.功能十分强大.

  8. android设置系统横屏方案

    效果如下: 实现方案: 1.ChangeOrientationService.java /** * @描述 强制旋转屏幕服务 * @作者 tll * @时间 2018/1/5 */ public cl ...

  9. FIN vs RST in TCP connections different

    question: The way I understand this, there are 2 ways to close TCP connection: send FIN flag send RS ...

  10. (转)OpenSystemArchitect - 根据数据库表逆向生成数据模型

    原文地址:http://www.cnblogs.com/zhaojin/archive/2011/04/14/2016478.html OpenSystemArchitect - 根据数据库表逆向生成 ...