加載ProPerties配置文件工具類

public class ProPertiesUtil {

    /**
     * @param fileName 文件名稱
     */
    public static Properties getProperties(String fileName) {
        Properties properties = new Properties();
        // 使用ClassLoader加載properties配置文件生成對應的輸入流
        InputStream in = ProPertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
        // 使用properties對象加載輸入流
        try {
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //返回Properties對象
        return properties;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章