public static Properties loadProperties ( final String path ) { if ( path != null ) { // try as file try { File file = new File ( path ) ; if ( file . exists ( ) ) { try { Properties p = new Properties ( ) ; p . load ( new FileInputStream ( file ) ) ; return p ; } catch ( Exception e ) { log . error ( "Error loading properties from file: " + path ) ; } } } catch ( Throwable e ) { log . debug ( e . getMessage ( ) , e ) ; } // try as resource InputStream inputStream = null ; try { inputStream = PropertyUtil . class . getResourceAsStream ( path ) ; if ( inputStream != null ) { try { Properties p = new Properties ( ) ; p . load ( inputStream ) ; return p ; } catch ( Exception e ) { log . error ( "Error loading properties from resource: " + path ) ; } } } catch ( Exception e ) { log . error ( "Error loading properties from resource: " + path ) ; } finally { if ( inputStream != null ) { try { inputStream . close ( ) ; } catch ( Throwable t ) { log . debug ( "Error closing: " + path , t ) ; } } } } // return empty Properties by default return new Properties ( ) ; }
Loads properties with given path - will load as file is able or classpath resource