Java读取property文件

Posted brake

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
            
        
    

  

以上是关于Java读取property文件的主要内容,如果未能解决你的问题,请参考以下文章