Java 读取配置文件

ublic static void initialize(){
  Properties props = new Properties();
  try {
   SERVER_PATH = getServerRoot();
   
   InputStream in = Config.class.getClassLoader().getResourceAsStream("config.properties");
   props.load(in);
   OFFICE_CODE = props.getProperty("office_code", StringUtils.EMPTY);
   CACHE_URL = props.getProperty("cache_url", StringUtils.EMPTY);
   APP_PATH = props.getProperty("app_path", StringUtils.EMPTY);
   CLASS_PATH = APP_PATH + File.separator + "WEB-INF" + File.separator + "classes" + File.separator;
   UPLOAD_PATH = props.getProperty("upload_path", StringUtils.EMPTY);
   
   AIRPORT_TAX10 = props.getProperty("airport_tax", StringUtils.EMPTY);
   PLANE_MODEL1 = props.getProperty("plane_model1", StringUtils.EMPTY);
   PLANE_MODEL2 = props.getProperty("plane_model2", StringUtils.EMPTY);
   PLANE_MODEL3 = props.getProperty("plane_model3", StringUtils.EMPTY);
   BBC_POLICY = props.getProperty("bbc_policy", StringUtils.EMPTY);
   
   SD_LINKMAN = props.getProperty("sd_linkman", StringUtils.EMPTY);
   SD_LINKMAN = new String(SD_LINKMAN.getBytes("ISO-8859-1"), "GBK");
   SD_CONTACT = props.getProperty("sd_contact", StringUtils.EMPTY);
   
   MONGODB_IP = props.getProperty("mongodb_ip",StringUtils.EMPTY);
   MONGODB_PORT = Integer.parseInt(props.getProperty("mongodb_port","27017"));
   MONGODB_DB_NAME = props.getProperty("mongodb_db",StringUtils.EMPTY);
   MONGODB_POOL_SIZE = Integer.parseInt(props.getProperty("mongodb_pool_size","50"));
   MONGODB_USER = props.getProperty("mongodb_user",StringUtils.EMPTY);
   MONGODB_PWD = props.getProperty("mongodb_pwd",StringUtils.EMPTY);
  }
  catch (Exception ex) {
   ex.printStackTrace();
  }
 }

你可能感兴趣的:(java)