惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
博客园 - Franky
罗磊的独立博客
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
V
V2EX
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
U
Unit 42
GbyAI
GbyAI
A
About on SuperTechFans
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
D
DataBreaches.Net
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog

博客园 - Valen

命令方式启动SQL服务 tomcat中显示文件目录 equals中NullPointerException问题解决 - Valen - 博客园 JSTL与EL表达式简单应用 - Valen - 博客园 Jsp重定向forward和sendRedirect的区别 Java,Hibernate,Sql之间数据类型对应表 转:Java调用正则表达式 - Valen - 博客园 Jsp中EL表达式不能显示的解决方法 Jsp中errorPage使用及web.xml配置 - Valen - 博客园 Install JSEclipse Method 备份你的手机通讯录到网络吧! vsftpd 配置 解决fedora11 root用户登录问题 Windows与Vmware下的Linux文件共享方法 Windows Live 设置 雷人签名 ob_start 用法 分页算法(1) 小沈阳 "不差钱" 改编版
JAVA读取Properties的六种方法
Valen · 2009-09-28 · via 博客园 - Valen

Posted on 2009-09-28 11:26  Valen  阅读(4875)  评论()    收藏  举报

  1. 1。使用java.util.Properties类的load()方法        
  2. 示例:        
  3. InputStream in = new BufferedInputStream(new FileInputStream(name));        
  4. Properties p = new Properties();        
  5. p.load(in);        
  6.       
  7. 2。使用java.util.ResourceBundle类的getBundle()方法        
  8. 示例:       
  9. ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());        
  10.       
  11. 3。使用java.util.PropertyResourceBundle类的构造函数        
  12. 示例:        
  13. InputStream in = new BufferedInputStream(new FileInputStream(name));        
  14. ResourceBundle rb = new PropertyResourceBundle(in);        
  15.       
  16. 4。使用class变量的getResourceAsStream()方法        
  17. 示例:        
  18. InputStream in = JProperties.class.getResourceAsStream(name);        
  19. Properties p = new Properties();        
  20. p.load(in);        
  21.       
  22. 5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法        
  23. 示例:        
  24. InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);        
  25. Properties p = new Properties();        
  26. p.load(in);        
  27.       
  28. 6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法        
  29. 示例:        
  30. InputStream in = ClassLoader.getSystemResourceAsStream(name);        
  31. Properties p = new Properties();        
  32. p.load(in);        
  33.       
  34. 补充        
  35.       
  36. Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法        
  37. 示例:       
  38. InputStream in = context.getResourceAsStream(path);        
  39. Properties p = new Properties();        
  40. p.load(in);