java读取properties资源文件的六种方法
2016-05-22 00:00
836 查看
摘要: 使用J2SE API读取Properties文件的六种方法
使用J2SE API读取Properties文件的六种方法
##1。使用java.util.Properties类的load()方法
示例:
##2。使用java.util.ResourceBundle类的getBundle()方法
示例:
##3。使用java.util.PropertyResourceBundle类的构造函数
示例:
##4。使用class变量的getResourceAsStream()方法
示例:
##5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例:
##6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例:
##补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:
使用J2SE API读取Properties文件的六种方法
##1。使用java.util.Properties类的load()方法
示例:
InputStream in=new BufferedInputStream(new FileInputStream(name)); properties p=new Properties(); p.load(in);
##2。使用java.util.ResourceBundle类的getBundle()方法
示例:
ResourceBundle rb=ResourceBundle.getBundle (name,Locale.getDefault());
##3。使用java.util.PropertyResourceBundle类的构造函数
示例:
InputStream in=new BufferedInputStream(new FileInputStream (name));ResourceBundle rb=newPropertyResourceBundle(in);
##4。使用class变量的getResourceAsStream()方法
示例:
InputStream in=JProperties.class.getResourceAsStream(name); properties p=newProperties(); p.load(in);
##5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例:
InputStream in=JProperties.class.getClassLoader().getResourceAsStream(name); properties p=newProperties(); p.load(in);
##6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例:
InputStream in=ClassLoader.getSystemResourceAsStream(name); properties p=newProperties(); p.load(in);
##补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:
InputStream in=context.getResourceAsStream(path); properties p=newProperties(); p.load(in);
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树