六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

JAVA属性文件的操作类Propertise

[复制链接]

升级  31.33%

25

主题

25

主题

25

主题

秀才

Rank: 2

积分
97
 楼主| 发表于 2013-1-15 02:48:16 | 显示全部楼层 |阅读模式
 
J2SE API读取Properties文件六种方法

http://webservices.ctocio.com.cn/115/8689615.shtml
 

<div style="margin: 0px; padding: 0px;">1。使用Java.util.Properties类的load()方法
  示例:InputStreamin=lnewBufferedInputStream(newFileInputStream(name));
  Propertiesp=newProperties();
  p.load(in);
  2。使用java.util.ResourceBundle类的getBundle()方法
  示例:ResourceBundlerb=ResourceBundle.getBundle(name,Locale.getDefault());
  3。使用java.util.PropertyResourceBundle类的构造函数
  示例:InputStreamin=newBufferedInputStream(newFileInputStream(name));
  ResourceBundlerb=newPropertyResourceBundle(in);
  4。使用class变量的getResourceAsStream()方法
  示例:InputStreamin=JProperties.class.getResourceAsStream(name);
  Propertiesp=newProperties();
  p.load(in);
  5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
  示例:InputStreamin=JProperties.class.getClassLoader().getResourceAsStream(name);
  Propertiesp=newProperties();
  p.load(in);
  6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
  示例:InputStreamin=ClassLoader.getSystemResourceAsStream(name);
  Propertiesp=newProperties();
  p.load(in);
  补充
  Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
  示例:InputStreamin=context.getResourceAsStream(path);
  Propertiesp=newProperties();
  p.load(in);
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表