smdt_wyd
作者smdt_wyd·2014-12-26 17:01
系统工程师·oracle

configjava

字数 2870阅读 1509评论 0赞 0

package com.cigna.etl.email.config;

 

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Properties;
import org.apache.log4j.Logger;

public class Config
{
  // private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(Contents.BUNDLE_NAME);
 
   protected static final Logger logger = Logger.getLogger(Config.class);
   private static final String CONFIG_FILE_NAME = "sysconfig.properties";
   private static final Properties pro = new Properties();

   static {
     logger.debug("Begin Loading sysconfig.properties>>>>>>>>>>>>>>>>");

     String path = Config.class.getProtectionDomain().getCodeSource().getLocation().getFile();
     System.out.print(path);
     logger.debug("Config path one>>>>>>>" + path);
     try
     {
       path = URLDecoder.decode(path, "ISO-8859-1");

       String filePath = new File(path).getParentFile().getAbsolutePath() + "//" + "sysconfig.properties";
       logger.debug("Config path two>>>>>>>" + filePath);

       InputStream ips = new BufferedInputStream(new FileInputStream(filePath));
       pro.load(ips);
     }
     catch (UnsupportedEncodingException e1) {
       logger.error(e1.getMessage());
     }
     catch (IOException e2) {
       logger.error(e2.getMessage());
     }

     logger.debug("sysconfig.properties>>>>>>>>>>>>>>>>" + pro);
     logger.debug("End Loading sysconfig.properties>>>>>>>>>>>>>>>>");
   }
 
 public static String getConfig(String key)
 {
//  String result = "";
//  
//  if(key != null && !"".equals(key.trim()))
//  {
//   result = RESOURCE_BUNDLE.getString(key);
//   
//  }
//  
//  return result;
  
    String result = "";

      if ((key != null) && (!("".equals(key.trim())))) {
        result = pro.getProperty(key);
      }

      return result;
 }
}

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

  • USP_SWAP_DB
    评论 0 · 赞 0
  • IproDaoImpl
    评论 0 · 赞 0
  • 2014122206
    评论 0 · 赞 0
  • db2权限
    评论 0 · 赞 0
  • 性能优化--文摘1
    评论 0 · 赞 0
  • 相关文章

    相关问题

    相关资料

    X社区推广