package com.opzoon.app.airchina.util; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class ConfigUtil { private final static Properties prop = new Properties(); private static ConfigUtil instance; private ConfigUtil() { InputStream is=null; is=this.getClass().getClassLoader().getResourceAsStream("conf"+File.separator+"config.properties"); if (null!=is) { try { prop.load(is); } catch (IOException e) { e.printStackTrace(System.err); } catch (Exception ex) { ex.printStackTrace(System.err); } finally { try { if(null!=is) { is.close(); is=null; } }catch(IOException e) { e.printStackTrace(); } } } else { System.out.println("无法找到配置文件:"); }//end if -else } public String getProperty(String key) { String value; if (prop.containsKey(key)) { value = (String) prop.get(key); } else { value = ""; } return value; } public static ConfigUtil getInstance(){ if(instance == null){ instance = new ConfigUtil(); System.out.println("---- getInstance new is called"); } return instance; } public static void main(String args[]){ System.out.println("xxxxxLOCAL_PATH="+new ConfigUtil().getProperty("LDAP_PATH")); System.out.println("xxxxxLOCAL_PATH="+new ConfigUtil().getProperty("FTP_PATH")); } public static String getStaticProperty(String key) { return getInstance().getProperty(key); } }