public static String getConfigKey(String key) {String fName = "aa.properties";String keyVal = "";Properties props = null;String url = StringUtils.class.getClassLoader().getResource("/").getPath()+ fName; /*從根目錄讀取設定檔 String fileName = ""; if(File.separatorChar == '\\') fileName = "C:\\"+fName; else fileName = "/"+fName; */ //log.info("設定檔地址----------"+url); File file = new File(url); if (!file.isFile()) { return null; } if (file.exists()) { FileInputStream fis = null; try { fis = new FileInputStream(file); } catch(FileNotFoundException e2) { log.info(file + "讀取設定檔錯誤。"); e2.printStackTrace(); } props = new Properties(); try { props.load(fis); fis.close(); keyVal = props.getProperty(key); if (keyVal == null) { log.error("設定檔中沒有名為:" + key + "的KEY值。"); } if (keyVal != null && keyVal.endsWith("\"")){ keyVal = keyVal.replaceAll("\"", ""); } } catch(IOException e) { e.printStackTrace(); log.info(file + "讀取設定檔中屬性值錯誤。"); } } else { log.info(file + "設定檔沒有找到。"); } return keyVal; }