There is probably a real easy solution for this but I am just missing it. The program is supposed to take an input file and then compare it to another file with a list of keywords and output the list of keywords with the number of times they occur in the test file (along with other tasks already achieved). The test file would have punctuation as well and I haven't quiet figured out how to omit those characters yet either. Any advise would be appreciated, assuming I am not completely off and need to rewrite the whole thing
import java.util.*;
import java.io.*;
import java.lang.*;
public class Project4 {
public static void main(String[] args) throws Exception
{
java.io.File file = new java.io.File("keywords.txt");
java.io.File testFile = new java.io.File("TestFile.txt");
Set<String> set = new HashSet<String>();
List<String> testList = new ArrayList<String>();
Scanner input = new Scanner(file);
Scanner testInput = new Scanner(testFile);
while (input.hasNext())
{
set.add(input.next());
// System.out.println(set);
}
TreeSet<String> treeSet = new TreeSet<String>(set);
//System.out.println(treeSet);
while (testInput.hasNext())
{
testList.add(testInput.next());
}
input.close();
TreeMap<String, Integer> map = new TreeMap<String, Integer>();
System.out.println(testList);
Iterator<String> iteratorSet = set.iterator();
Iterator<String> iteratorTest = testList.iterator();
while (iteratorSet.hasNext())
{
String key = iteratorSet.next();
while (iteratorTest.hasNext())
{
if (map.get(key) == null)
{
map.put(key, 0);
}
else
{
int value = map.get(key).intValue();
value++;
map.put(key,value);
}
}
}
Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
for (Map.Entry<String, Integer> entry: entrySet)
System.out.println(entry.getValue() + "\t" + entry.getKey());
}
}