加载properties文件属性的Java工具类实现
来源:互联网 发布:linux基础知识学习 编辑:程序博客网 时间:2024/05/16 08:50
今天有点无聊,写了一个如何读取properties文件配置信息的类,其实这个功能在java.util包中已经有了相应的功能,但是我还是想要实现一下,以检测自己的编程能力
代码如下:
import java.io.BufferedReader;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import java.util.HashMap;public class Properties { static HashMap<String, String> hashMap = new HashMap<String, String>(); @SuppressWarnings("resource") public static void getProperties(String properties) throws IOException{ BufferedReader bufferedReader = null; bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(properties))); String str = null; while ((str=bufferedReader.readLine()) != null) { int index = str.indexOf("="); if(index != -1){ hashMap.put(str.substring(0,index).trim(), str.substring(index+1).trim()); } } } public static String getProperties(String key, String defalutvalue){ String value = hashMap.get(key); if(value == null){ value = defalutvalue; } return value; } public static String getProperties(String propertiesFileName, String key, String defalutvalue) throws IOException{ getProperties(propertiesFileName); return getProperties(key, defalutvalue); } public static void main(String[] args) throws IOException { String valueString = getProperties("C:/Users/Kin.Liufu/Desktop/一点小心得/config.properties","userName","kin"); System.out.println(valueString); }}
0 0
- 加载properties文件属性的Java工具类实现
- java加载properties工具类
- 关于加载Spring加载外部文件属性.properties的问题
- java 读取properties文件属性
- java properties 的工具类
- 使用java读写properties文件属性
- 热加载Properties 工具类
- 加载properties文件工具类
- 加载properties配置文件工具类
- java 对 xxx.properties资源文件属性的修改,添加
- JAVA基础(五)·Properties类读取文件属性信息
- JAVA Properties工具类
- JAVA Properties工具类
- java读取Properties文件的工具类
- java实现读取flash的swf文件属性
- java properties 文件的加载
- 加载Properties文件工具类:LoadConfig
- java.util.Properties工具类
- 瀑布流效果RecycleView+CardView
- UUID already exists
- 使用Xcode GPU Frame Caputre教程
- php判断是否为手机站
- 【C++11新特性】 Lambda表达式
- 加载properties文件属性的Java工具类实现
- C语言的预处理
- DataTime减去1月
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- InboxLayout 多重listview 动态显示 手势操作
- [IMX6Q][Android5.1]如何获取Android5.1 Source Code
- 10008---正则表达式基本语法
- Linux 网卡驱动学习(四)(缓存描述符 Buffer Description)
- Android ActionBar 创建 及动态改变