Java read the property file

 

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

  

Guess you like

Origin www.cnblogs.com/Brake/p/11442828.html