Properties类的使用和源码浅析
2016-04-25 11:09
316 查看
Properties类代表持久化属性集合。Properties能够保存到流中,也可以从流中加载。而每一个key和它对应的value在属性列表中用string来表示。
一、类的继承关系
从继承关系图中可以知道Properties的内部是有Hashtable实现的。
二、部分方法的源码
load(InputStram)
load0
setProperty(String,String)
getProperty(String)
三、内部类
四、使用Properties读取Java项目不同位置的properties文件
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Map.Entry; import java.util.Properties; public class PropertiesTest { public static void main(String[] args) throws IOException { //1.读取项目下的properties文件 //File file = new File("test.properties"); //2.读入项目下新建文件夹中的properties文件 //File file = new File("lib/test.properties"); //3.读取src下的properties文件 //File file = new File("src/test.properties"); //4.读取package下面的properties文件,采用类加载 String path = PropertiesTest.class.getClassLoader().getResource("com/test/px/test.properties").getPath(); File file = new File(path); InputStream inStream = new FileInputStream(file); Properties props = new Properties(); props.load(inStream); for(Entry<Object, Object> entry: props.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); System.out.println(key+" = "+value); } } }
相关文章推荐
- tomcat 配置客户端证书认证
- linux下Vim小技巧
- centos6源码编译安装MySQL5.6
- GitLab CE 9-3-stable源码安装手册(Centos6/REHL6)
- 在Mac上安装OpenCV
- CentOS下查看进程和删除进程
- org.apache.struts2.json.JSONWriter can not access a member of class
- Linux下更新build-tools-20.0.0显示The package filter removed all packages.
- Linux mount挂载目录
- linux修改挂载目录
- 怎样用sourceTree将自己本地的项目上传到github网站上
- 解决SharePoint2013 升级后的网站集瘫痪的问题。“很抱歉,出了问题。文件未找到”
- linux 挂载硬盘到目录
- 网站克隆器神器AWWWB.COM
- centos install pssh
- centos 7 pip yum
- Xen常用命令
- java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntim [问题点数:40分,结帖人wangxiaohua_001]
- ZOJ 3941 Kpop Music Party
- s:property标签