Java 读取配置文件 Properties

时间:2014-06-27 16:00:15   收藏:0   阅读:228
            String filePath="src/cn/ac/iscas/pebble/ufe/conf/id.properties";
            InputStream in = new BufferedInputStream(new FileInputStream(filePath));
            int i = 0;
            Properties p = new Properties();
            p.load(in);
p.getProperty(key);

还有一个方式如下:

public class ConfigUtils {
    
    private static final ResourceBundle baseBundle = ResourceBundle.getBundle("cn/ac/iscas/pebble/ufe/conf/id");

    public static String getValue(String key) {
        return baseBundle.getString(key).trim();
    }

首先 id所在的大目录必须在classpath下。如下所示:

Navigator下查看.classpath文件:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
…………

 

 

Java 读取配置文件 Properties,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!