[Java configuration] Parse the Properties file

111

/ ** 
 * 
 * @ Function: Properties file parsing 
 * @ Author: Herun 
 * @ Creation Date: 2014-3-4 
 * @ version: V1.0 
 * / 
public  class ParseProperties { 

    Private  static Logger Logger Logger.getLogger = ( ParseProperties. Class ); 

    / ** 
     * Relative path 
     * 
     * @return 
     * / 
    public  static Properties getProperties () { 
        Properties p = null ;
         try {
             // Generate input stream 
            InputStream ins = ParseProperties. Class.getResourceAsStream ("../../../ jdbc.properties" );
             // Generate properties object 
            p = new Properties ();
             try { 
                p.load (ins); 
            } catch (Exception e) { 
                e.printStackTrace (); 
            } 

        } catch (Exception e) { 
            logger.error ( "Error getting system configuration file jdbc.properties:" + e); 

        } 
        return p; 
    } 

    public  static  void main (String [] args) { 
        System.out.println (ParseProperties.getProperties (). getProperty ( "port"));
    }

}

 

Guess you like

Origin www.cnblogs.com/kikyoqiang/p/12701446.html