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 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
随机推荐
- tomcat源码 Connector
Connector容器主要负责解析socket请求,在tomcat中的源码位于org.apache.catalina.connector和org.apache.coyote包路径下:通过上两节的分析, ...
- Java线程池管理及分布式Hadoop调度框架搭建
平时的开发中线程是个少不了的东西,比如tomcat里的servlet就是线程,没有线程我们如何提供多用户访问呢?不过很多刚开始接触线程的开发工程师却在这个上面吃了不少苦头. 怎么做一套简便的线程开发模 ...
- Excel导出文件流下载
Controller.cs @CrossOrigin(allowCredentials="true", allowedHeaders="*", methods= ...
- AS3面试题 个人理解
现在as3面试 感觉就那几个题目来回考.有了题库,大家都看了 都答上来了 题目本身也就失去了考核的意义.而且题目本身也有很多偏的(不常用的)在考. 真正的面试官现在肯定也不会把笔试成绩当作标准.所谓: ...
- 【模态窗口-Modeldialog】提交请求时禁止在新窗口打开页面的处理方法
在使用Window.ShowModalDialog()打开模态窗口后,在模态窗口内提交时总是会在新窗口中打开. 解决办法: 在要弹出的窗口的<head>之间加: <base targ ...
- vue之v-on
我们可以用 v-on 指令绑定一个事件监听器,通过它调用我们 Vue 实例中定义的方法: <!DOCTYPE html> <html lang="en"> ...
- 简单的单进程FTP服务器的实现
一.功能说明: 1.本程序基于socket实现客户端与服务器端的单进程交互 2.用到的用户名:whw,密码abc123——服务器端密码的验证利用hashlib模块进行MD5的编码以确保通信安全. 3. ...
- MySQL存储过程 事务transaction
MySQL 中,单个 Store Procedure(SP) 不是原子操作,而 Oracle 则是原子的.如下的存储过程,即使语句2 失败,语句 1 仍然会被 commit 到数据库中: create ...
- Vue3.0项目快速搭建
安装安装vue-cli npm install -g @vue/cli # 或者 yarn global add @vue/cli 创建项目 vue create hello-world 至此项目搭建 ...
- 性能测试day02_预习知识
在进入第二天的学习之前,我想我们需要提前先了解一下基础的知识,所以这一篇主要讲解的就是预习课程,关于协议和抓包的讲解(原理和工具). 可以说基于服务器的性能一般都是基于协议的,所以我们就需要懂协议,以 ...