使用J2SE API读取Properties文件的六种方法:
1.使用java.util.Properties类的load()方法
示例: InputStream in = lnew 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 = new PropertyResourceBundle(in);
4.使用class变量的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
5.使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
6.使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);
补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:InputStream in = context.getResourceAsStream(path);
Properties p = new Properties();
p.load(in);
分享到:
相关推荐
J2SE API读取Properties文件六种方法,相当经典。
使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name)); Properties p = new Properties(); p.load(in); 2。使用java.util....
NULL 博文链接:https://hailong886.iteye.com/blog/297368
API读取Properties文件的六种方法2009-03-02 08:57使用J2SE API读取Properties文件的六种方法 1。使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream...
J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API
J2SE基础知识大全 J2SE基础知识大全 J2SE基础知识大全
J2SE基础源代码
J2SE课件J2SE课件J2SE课件J2SE课件J2SE课件J2SE课件
j2se1.5中文api
j2se编写的午饭随机选取系统,方便不知道中午吃什么的用户,随机抽取中饭吃什么。其中技术有:随机数,文件读取,j2se,JTable,DefaultTableModel,隐藏文件,显示文件等等!
j2se doc 中文版 j2se doc 中文版 j2se doc 中文版 j2se doc 中文版
J2EE与J2SE项目中路径获取的几种方式
很好的j2se的API
J2SE桌面应用开发 J2SE桌面应用开发J2SE桌面应用开发 J2SE桌面应用开发 J2SE桌面应用开发
j2se api 中文版 j2se api 中文版 j2se api 中文版
J2SE 教程
zxing/zxing-j2se-1.7.jar包, 包含类 com.google.zxing.StringsResourceTranslator.class com.google.zxing.client.j2se.BufferedImageLuminanceSource.class ...
j2se是学好java的基础,其中必须掌握api文档的一些包
j2se中文API,详细介绍基础的类以及方法
J2SE概述