Tag: 字频

文件中的字数统计频率

我有一个目录,其中有1000个txt.files。 我想知道每一个字在1000文档中发生了多少次。 所以说甚至“牛”这个词在X中出现了100次,它仍然算作一个。 如果它出现在另一个文档中,则会增加1。 因此,如果每个文档中都出现“cow”,则最大值为1000。 如何在不使用任何其他外部库的情况下轻松实现此目的。 这是我到目前为止所拥有的 private Hashtable getAllWordCount() private Hashtable getAllWordCount() { Hashtable result = new Hashtable(); HashSet words = new HashSet(); try { for (int j = 0; j < fileDirectory.length; j++){ File theDirectory = new File(fileDirectory[j]); File[] children = theDirectory.listFiles(); for (int i = 0; i < children.length; i++){ Scanner scanner […]