将文件中的参数读取成Map

/**
     * 将文件中的参数读取成Map
     * @param basePath 参数文件路径
     * @return Map参数集
     */
    public static Map<String,String> FindConfigParam(String basePath){
        Map<String,String> map = new HashMap<String,String>();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(basePath+"/"+"config.inc"))));
            String lineValue;
            while((lineValue=br.readLine())!=null){
                if(!lineValue.startsWith("##")){
                    String[] paramVlaue = lineValue.split("=");
                    if(paramVlaue.length==1){
                        map.put(paramVlaue[0], "");
                    }else{
                        map.put(paramVlaue[0], paramVlaue[1]);
                    }
                }
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        return map;
    }

posted on 2012-06-18 14:10  jackvc  阅读(150)  评论(0编辑  收藏  举报

导航