PropertiesUtils(普遍做法)

public class PropertiesUtil{

  private static Properties properties;

  static{

    InputStream in = null;

    try{

      in = PropertiesUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");

      properties = new Properties();

      properties.load(in);

    }catch(Exception e){

      e.printStackTrace();

    }finally{

      try{

        if(in != null){

          in.close();

        }

      }catch(Exception e){

        e.printStackTrace();

    }

  }

  }

   public static Properties getPropertis(){

    return properties;  

  }

  

}

原文地址:https://www.cnblogs.com/lingtiaoti/p/9887232.html