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 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
随机推荐
- 开始使用GoJS
GoJS是一个用于实现交互式图表的JavaScript库.本页将向您展示使用GoJS的必要条件. 由于GoJS是一个依赖于HTML5功能的JavaScript库,因此您需要确保您的页面声明它是一个HT ...
- ckeditor_4.5.10_full,ckfinder_aspnet_2.6.2,插件使用
1.ckfinder文件上传的权限: public override bool CheckAuthentication() { // WARNING : DO NOT simply return &q ...
- 用windows自带的ftp.exe实现断点续传的方法
摘自http://www.jb51.net/article/10604.htm 动画下载地址: http://www.chinesehack.org/soft/book/goonftp-jc.rar ...
- HashSet的自定义实现
package com.cy.collection; import java.util.HashMap; /** * HashSet自定义实现 * 是使用hashMap实现的 * 可以看一下HashS ...
- CentOS搭建SVN服务器,并通过Apache HTTP方式访问
摘要:本文主要讲述了在centos 6.5环境下搭建svn服务器,可通过svn:\\IP方式访问.同时由于部分公司内网端口限制,并不能访问外网的svn服务器,所以特地结合了apache服务器,使得可以 ...
- Android应用启动会白屏一下的解决办法
设置透明样式,如下:<activity android:name="com.hongfans.cvi.ui.MainActivity" android:configChang ...
- 主机、Docker时间与时区设置总结
最近在使用Docker容器时,部署java程序发现时间输出不对,在修改问题时总结如下. #date [-R] #查看主机时间 #timedatectl #查看主机时区 #tzselect ...
- JVM调优原理
JVM堆栈 栈是运行时的单位,而堆是存储的单位. 栈解决程序的运行问题,即程序如何执行,或者说如何处理数据:堆解决的是数据存储的问题,即数据怎么放.放在哪儿. 在Java中一个线程就会相应有一个线程栈 ...
- 关于dict的formkeys方法注意
使用容器中的元素生成k, v为统一值, 指向同一个内存地址 默认值指向同一个内存, 修改就全部修改 strvar = 'abcd' listvar = [] dictvar = {} dictvar ...
- BCGcontrolBar(二) 改变RIBBON字体
在xp系统下 BCGcontrolBar字体会发虚 这时候重新设置下字体就行了 在单文档的MainFram的onCreate中加入 CFont *font=m_wndRibbonBar.GetFont ...