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

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - 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);