|
1
2
3
4
5
6
7
8
9
|
#数据库配置信息DRIVER=com.mysql.jdbc.DriverURL=jdbc:mysql://localhost:3306/testuser=rwuserpassword=rwuser#路径配置信息path=D:\\Java\\jdk1.6.0_31\\bin |
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package iceinfo.bat.test;import java.util.ResourceBundle;public class TestResourceBundle { public static void main(String[] args) { String fileName="config";// config.properties它跟普通java类的命名规则完全一样: // - 文件名和包名是区分大小写 // - 扩展名 .properties 省略 // - 资源文件必须位于classpath下,如果在某个包下成在定义fileName时要加上包的名称,且包名区分大小写 // 如果是Web项目,不写包路径可以,此时将资源文件放在WEB-INF\classes\目录下就可以。 ResourceBundle paramBundle = ResourceBundle.getBundle(fileName); System.out.println(paramBundle.getString("DRIVER")); System.out.println(paramBundle.getString("URL")); System.out.println(paramBundle.getString("user")); System.out.println(paramBundle.getString("PASSWORD"));//这儿是区分大小写的 System.out.println(paramBundle.getString("path")); }} |
405




被折叠的 条评论
为什么被折叠?



