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. 在已有Windows系统基础上安装ubuntu后无Windows启动项

    1. 原系统为windows 2. 清出一个不用的分区给linux,使用windows磁盘管理器将该分区重新划分为两个分区,分别用于root和swap 3. 安装过程中ubuntu提示原系统为非UEF ...

  2. 【剑指offer】斐波那契数列非递归求解第N项

    public class Solution { public int Fibonacci(int n) { //错误输入处理 if(n<0) return -1; int pre = 1; in ...

  3. Ubuntu 14.10 下Hadoop HttpFS 配置

    因为hadoop集群中需要配置一个图形化管理数据的截面,后来找到HUE,那么在配置HUE的过程中,发现需要配置httpfs,因为配置了httpfs,hue才能去操作hdfs中的数据. HttpFs能干 ...

  4. hadoop 完全分布式安装

    一个完全的hadoop分布式安装至少需要3个zookeeper,3个journalnode,3个datanode,2个namenode组成. 也就是说需要11个节点,但是我云主机有限,只有3个,所以把 ...

  5. 廖雪峰Java4反射与范型-3范型-1什么是泛型

    1.为什么需要泛型? JDK提供了ArrayList,可以看作"可变长度"的数组: 比数组使用方便 示例1:如果使用ArrayList存储String类型: 需要强制转型 不方便, ...

  6. MySQL事务提交过程(转载)

    http://blog.csdn.net/sofia1217/article/details/53968214 上一篇文章我们介绍了在关闭binlog的情况下,事务提交的大概流程.之所以关闭binlo ...

  7. JS的正则表达式简介

    1.JS的正则表达式 1.1 简介 JS的正则表达式比较简单,总体上只分为两个功能:一个是test——用于匹配字符串是否符合规定的正则表达式规则:另外一个是exec——用于获取匹配到的数据. 1.2 ...

  8. Js学习(1)

    数据类型 简单数据类型 ◆number   数字类型 ◆string     字符串类型 ◆Boolean   布尔类型 ◆true      真 (正确的) ◆false     假(错误的) ◆u ...

  9. [SQL]用SQL语句断开某个数据库的所有活动连接

    USE master go IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[P_KillConnectio ...

  10. win10配置labelImg

    [引言]在目标检测中,需要用图像标注工具标注图像,如Labelme . labelImg等,本文使用的是LabelImg ,LabelImg在Ubuntu下很好部署, 在win10中有些地方要注意下, ...