word count frequency in document
<p>I have a directory in which I have 1000 txt.files in it. I want to know for every word how many times it occurs in the 1000 document. So say even the word "cow" occured 100 times in X it will still be counted as one. If it occured in a different document it is incremented by one. So the maximum is 1000 if "cow" appears in every single document. How do I do this the easy way without the use of any other external library. Here's what I have so far </p>

<pre><code>     private Hashtable&lt;String, Integer&gt; getAllWordCount()
     private Hashtable&lt;String, Integer&gt; getAllWordCount()
    {
        Hashtable&lt;String, Integer&gt; result = new Hashtable&lt;String, Integer&gt;();
        HashSet&lt;String&gt; words = new HashSet&lt;String&gt;();
        try {   
            for (int j = 0; j &lt; fileDirectory.length; j++){
                File theDirectory = new File(fileDirectory[j]);
                File[] children = theDirectory.listFiles();

                for (int i = 0; i &lt; children.length; i++){
                    Scanner scanner = new Scanner(new FileReader(children[i]));

                    while (scanner.hasNext()){
String text = scanner.next().replaceAll("[^A-Za-z0-9]", "");
                        if (words.contains(text) == false){
                            if (result.get(text) == null)
                                result.put(text, 1);
                            else
                                result.put(text, result.get(text) + 1);
                            words.add(text);
                        }
                    }
                }
                words.clear();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(result.size());
        return result;
    }
</code></pre>
