| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 编程开发 > Java教程 > J2SE基础类 > 文章正文 用户登录
五个最值得关注的
网络营销之google
Google Adsense改
王通:Google应该
Geesee广告计划详
Google Adsense将
Google AdSense开
Google AdSense (
Google AdSense推
Google Adsense即

J2SE API读取Properties文件六种方法           

J2SE API读取Properties文件六种方法

作者:佚名 来源:JR 更新:2006-8-25 21:05:35 错误报告 我要投稿

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

文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。