java-读取属性文件

Property类:

public static Properties loadLocalProperties(String fileName) {
        Properties property = new Properties();

        try {
            String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
            InputStream in = new BufferedInputStream(new FileInputStream(path + "/" + fileName));
            property.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return property;
    }

 

ResourceBundle类:

public static ResourceBundle loadLocalProperties2(String fileName) {
        return ResourceBundle.getBundle(fileName, Locale.getDefault());
    }

 

posted @ 2016-10-18 20:15  刨根问底_liang  阅读(268)  评论(0编辑  收藏  举报