读取*.cfg文件,保存进HashMap
/** * 文本内容样式 * [SYSTEM] * #数据库类型 * database=oracle */private void init(){ BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(filePath)); String line; while ((line = reader.readLine()) != null) { line = line.trim(); //如果行长度为0或者首字节是#或[ if ((line.length() == 0) || (line.charAt(0) == '#') || (line.charAt(0) == '[')) { continue; } int splitPos = line.indexOf('='); if (splitPos != -1) { //等号前为键 等号后为值 configMap.put(line.substring(0, splitPos).toLowerCase(Locale.ENGLISH).trim(), line.substring(splitPos + 1, line.length()).trim()); } } } catch (Exception e) { // TODO: handle exception } finally { // 关闭文件句柄 try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } }1 楼 gaoxiaoweiandy 2012-01-05