java web项目读取properties文件

来源:互联网 发布:委托软件开发合同 编辑:程序博客网 时间:2024/04/29 12:27

一、通过jdk提供的java.util.Properties类。


InputStream input = this.getClass().getClassLoader().getResourceAsStream("文件名");

Properties properties = new Properties();

properties.load(input);




二、通过java.util.ResourceBundle类来读取,这种方式比使用Properties要方便一些。

Resourcebundle resource = ResourceBundle.getBundle("文件名");

String value = resource.getString("文件中定义的名字");

原创粉丝点击