PropertiesUtils
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的更多相关文章
- Property工具类,Properties文件工具类,PropertiesUtils工具类
Property工具类,Properties文件工具类,PropertiesUtils工具类 >>>>>>>>>>>>>& ...
- PropertiesUtils(普遍做法)
public class PropertiesUtil{ private static Properties properties; static{ InputStream in = null; tr ...
- iframe无刷新跨域并获得返回值
参考:http://geeksun.iteye.com/blog/1070607 /** * iframe跨域提交大数据 * @param action 跨域地址 * @param arr [ {na ...
- Properties类使用
package com.emolay.util; import java.io.IOException; import java.io.InputStream; import java.util.Pr ...
- Redis常用方法
首先构建非切片连接池jedisPool对象,写好配置redis连接的方法. /** * 构建redis切片连接池 * * @param ip * @param port * @return Jedis ...
- 使用SparkSQL实现多线程分页查询并写入文件
一.由于具有多张宽表且字段较多,每个宽表数据大概为4000万条,根据业务逻辑拼接别名,并每张宽表的固定字段进行left join 拼接SQL.这样就能根据每个宽表的主列,根据每个宽表的不同字段关联出一 ...
- Servlet & JSP - Java Web 访问资源的路径问题
假设 Web 工程的目录结构如下图所示,并且 HelloServlet 配置为 @WebServlet(name = "helloServlet", urlPatterns = { ...
- Java获取.properties配置文件某一项value根据key值
public static String getProperty(String key){ InputStream in = PropertiesUtils.class.getResourceAsSt ...
- jsp-2 简单的servlet连接mysql数据库 增删改查
连接mysql数据库的操作 有增删改查 用的包有 commons-lang3-3.5 mysql-connector-java-5.1.40-bin 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
随机推荐
- CentOS 7下NFS Server作rootfs时的兼容性问题
最近新装CentOS 7,发现原先CentOS 6.3下可用的一块ARM Dev board不能用了,表现为VFS mount挂载rootfs失败. 使用WireShark发现,服务器对client发 ...
- [蓝桥杯]ALGO-116.算法训练_最大的算式
问题描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号 ...
- C++中sort函数小结
我们都知道,sort函数是C++标准库<algorithm>中的一个库函数.它的功能是对数组/容器中的元素进行排序.用法示例如下: 一.对数组进行排序 示例: int a[] = {1,3 ...
- bzoj4020: 未来程序·改
只需写一个解释器 第一次预处理将输入进行分词,分割出 关键字,运算符,变量/函数名,整数常量,并对变量/函数名离散化以便处理 第二次预处理建语法树,每个节点存节点类型,变量定义表等信息 运行时在语法树 ...
- 峰Redis学习(9)Redis 集群(概述)
第一节:Redis 集群概述 redis cluster是去中心化,去中间件的,也就是说,集群中的每个节点都是平等的关系,都是对等的,每个节点都保存各自的数据和整个集群的状态.每个节点都和其他所有节点 ...
- python 判断返回结果 in用法
AA=data[0]["content"] if U"已签收" in AA:(判断 AA里面有没有包含 "已签收的字样") print &q ...
- 学习笔记之Nearest-Neighbour Searching with PostGIS
PostgreSQL: Documentation: 10: 7.8. WITH Queries (Common Table Expressions) https://www.postgresql.o ...
- bundle adjustment 玩具程序
结合 bundle adjustment原理(1) 和 Levenberg-Marquardt 的 MATLAB 代码 两篇博客的成果,调用MATLAB R2016a中 bundleAdjustmen ...
- 基础回顾之List集合
1.List集合的的contains()方法底层调用的是equals()方法,当比较自定义对象时,需要重写比较对象的equals()方法 2.List集合的remove()方法底层依赖的也是equal ...
- Visual Ribbon Editor for CRM 连接