<b>J2SE API读取Properties文件的六种办法</b>[Java编程]
本文“<b>J2SE API读取Properties文件的六种办法</b>[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
利用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);
以上是“<b>J2SE API读取Properties文件的六种办法</b>[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |