属性文件的读取二法

Posted on 2006-07-06 18:13 负人博客 阅读(366) 评论(0)  编辑  收藏 所属分类: JAVA技术

1 Properties类直接读取属性文件
 
public class Test {
 public static void main(String[] args) {
  InputStream is = Test.class.getResourceAsStream("nojar.properties");
  if (is == null)
   System.out.println("文件找不到");
  Properties prop = new Properties();
  try {
   prop.load(is);
  } catch(Exception e) {
   e.printStackTrace();
  }
  System.out.println(prop.getProperty("test"));
 }
}
2 通过ResourceBundle读取属性文件

public class Test {
 public static void main(String[] args) {
  ResourceBundle rb = ResourceBundle.getBundle("test");
  System.out.println(rb.getString("test"));
 }
}


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 26, comments - 5, trackbacks - 0, articles - 8

Copyright © 负人博客