Java读取property文件

 

public static Properties loadProps(String fileName) {
        Properties properties = null;

        InputStream inputStream = null;
        try {
            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
            if (inputStream == null) {
                throw new FileNotFoundException(fileName);
            }
            properties = new Properties();
            properties.load(inputStream);

        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            closeStream(inputStream);
        }
        return properties;
    }

    private static void closeStream(InputStream inputStream) {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

  

posted @ 2019-09-01 17:01  ibrake  阅读(424)  评论(0编辑  收藏  举报