星期四, 五月 24, 2007

java 读 properties格式文件


package hddqcs.datamining.venus.venusfile;

import hddqcs.datamining.venus.common.DMLogger;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 *
 * COPYRIGHT(C) Hitachi Global Storage Technologies, Inc.
 * All Rights Reserved.
 *
 * This Class is to reading the process config file
 *
 *  eg. etl_venusProcess.properties
 *
 * @author liuqact
 */
public class ReadingProcessProsFile {
 Logger logger = Logger.getLogger(ReadingProcessProsFile.class.getName());
 public Properties getProperties(String dir,String fileName)throws FileNotFoundException,IOException,Exception {
  // TODO Auto-generated method stub
  try{
   Properties pros = new Properties();
   InputStream prosFile = new FileInputStream("Log4j.properties");
   pros.load(prosFile);
  return pros;
  }catch(FileNotFoundException e){
   logger.error("Properties file inputted is not exist");
   throw e;
  }catch(IOException e){
   logger.error("Reading Properties file inputted failed");
   throw e;
  }catch(Exception e){
   logger.error("get values from Properties file inputted failed");
   throw e;
  }
 }
}

没有评论: