java 读取配置文件

        /*
         * java工程下读取配置文件
         * 1. rt.jar --> java.util --> ResourceBundle.class 
         * 2. 配置文件后缀名必须为.properties,内容必须为键值对 
         *         key1=value1 
         *         key2=value2 
         *         ... 
         * 3. test.properties配置文件(所在文件夹)须在src下或Source Folder下
         *    如果配置文件所在的文件夹不在src下或者为普通文件夹可以通过Build Path --> Use as Source Folder转为Source Folder
* 读取配置文件时不需要加文件的后缀名 * 4. 读取配置文件成功后,读取文件内容时通过key获取value */ ResourceBundle bundle = ResourceBundle.getBundle("test"); System.out.println(bundle.getString("key1")); System.out.println(bundle.getString("key2"));
posted @ 2016-06-30 18:27  蒲木杉  阅读(318)  评论(0编辑  收藏  举报