本帖最后由 cobasta 于 2012-03-10 21:34:51 编辑

解决方案 »

  1.   

    public void read(){
       try{
       Map< String, Integer> map=new HashMap<String, Integer>();
       int all=0;
           for (File file : new File("e:\\newgroups\\alt.atheism").listFiles()) {
                    //顺次统计文件夹下的每个文件
             InputStreamReader in=new InputStreamReader(new FileInputStream(file));
             int b;
        String str="";
        while((b=in.read())!=-1){
        char ch=(char)b;
        if(!Character.isLetter(ch))
         {
                                       //读取字符,如果不是字母,则把之前积累的字符串加到MAP结构中
        if(str!="") {
        Integer n=map.get(str);
                                                             //区分原有字符串和新增字符串
        map.put(str,n==null?1:n+1);
        all++;
        str="";
        }
        continue;
         }
        else  
        {//字符是字母,添加到字符串后部
        if(Character.isUpperCase(ch))
        ch=Character.toLowerCase(ch);//大写字母转换为小写
        str+=ch;
       
        }
        }
        System.out.println(all);
         }
       } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }    
       }
      

  2.   

    这不是MapReduce的wordcount算法嘛不过那个是分布式的,当我没说好了 = =我觉得缩略词应该跟原词没啥关系,算两种不同的单词就好了。