码迷,mamicode.com
首页 > 编程语言 > 详细

Java读取property文件

时间:2019-09-01 18:58:02      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:str   tst   return   stack   puts   ret   filename   rop   extc   

 

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();
            }
        }
    }

  

Java读取property文件

标签:str   tst   return   stack   puts   ret   filename   rop   extc   

原文地址:https://www.cnblogs.com/Brake/p/11442828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!