properties文件工具类
来源:互联网 发布:中考倒计时软件下载 编辑:程序博客网 时间:2024/05/22 01:32
最近因为要使用到properties文件,所以写了个工具类。对它进行读取操作。
- properties文件内容
name=jasonage:1222person:JAKE
- 工具类代码
import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.logging.Log; //公共的日志记录import org.apache.commons.logging.LogFactory; //日志记录Factory/** * Properties工具类 * @author lzx * 2017.05.28 */ public class PropertiesUtil { private static final Log log = LogFactory.getLog(PropertiesUtil.class); private static Properties env = new Properties(); private static String fileProperties; //文件名 PropertiesUtil(){} //空的构造方法 //参数实例化类时 fileProperties为要读的文件名 PropertiesUtil(String fileProperties){ this.fileProperties=fileProperties; try { InputStream is = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileProperties); env.load(is); is.close(); } catch (Exception e) { log.error(e); } } /** * 取属性值 * @param key * @return */ public static String getProperty(String key){ return env.getProperty(key); } /** * 设置属性值 * @param key * @param value */ public static void setProperty(String key, String value){ try{ File file = new File(PropertiesUtil.class.getClassLoader().getResource(".").getPath()+File.separator+fileProperties); FileOutputStream outStream = new FileOutputStream(file); env.setProperty(key, value); //写入properties文件 env.store(outStream, null); } catch (Exception ex) { log.error(ex); } } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(new PropertiesUtil("system.properties").getProperty("man")); // new PropertiesUtil("system.properties").setProperty("age","liaozexu"); //System.out.println(PropertiesUtil.class.getClassLoader().getResource(".").getPath()); } }
阅读全文
0 0
- properties文件工具类
- Properties资源文件工具类
- Properties文件读取工具类
- 获取properties文件工具类
- 读取properties文件,工具类。
- 加载properties文件工具类
- 工具类: Properties文件载入
- Properties文件读取工具类
- Properties文件读取工具类
- Properties文件载入工具类
- Properties文件载入工具类
- 读取properties文件工具类
- properties文件读取工具类
- 能保存Properties文件注释的Properties工具类
- Properties的工具类,用于读取外部文件Properties
- 读取properties文件的工具类
- 【java工具类】properties文件操作
- java 解析properties文件 工具类 通用
- openalpr在windows10 x64 vs2015编译
- "less is more",用"less”命令查看linux文本文件
- STC15F104E (8脚单片机)实现蓝牙串口控制舵机转向
- sublime text 安装教程与常用插件安装与卸载方法
- poj2976:dropping tests(0/1分数规划)
- properties文件工具类
- 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序解决办法
- 首个区块链标准《区块链 参考架构》正式发布
- 安卓应用启动时黑屏和白屏的原因及解决办法
- Java 内存分配全面浅析(转载)
- JAVA生成验证码
- poj3904 Sky Code —— 唯一分解定理 + 容斥原理 + 组合
- Android中的广播Broadcast
- 201. Bitwise AND of Numbers Range