注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
清除不明进程msser 珊瑚QQ病毒防
用Norton Internet Security拦截
Win2000 Server入侵监测揭秘
入侵NTserver典型途径攻击基础
简单三步走堵死SQLServer注入漏洞
安全配置Norton Security2004
Windows 2000 Server 系统安装后
DNS 系统设定例--5.named.boot 的
用Web方式管理Imail Server
IMailServer配置技巧-完整DNS设定
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> Java >> 文章正文
J2SE API读取Properties文件六种方法
作者:佚名  来源:不详  点击:  更新:2006-12-19
简介:

使用J2SEAPI读取Properties文件的六种方法

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);






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务