Im trying to populate the map with the word as the key, and the occurences of that word as the value. The code runs but the results are not accurate. Can anyone see where the code is going wrong here? thanks!
public static void tokenize() {
File file = new File ("textFile.txt");
try {
FileReader fr = new FileReader(file.getName());
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
while(line!=null) {
String[] array = line.split(" ");
for(String s : array) {
if(staticHashMap.containsKey(s)) {
int value = staticHashMap.get(s);
staticHashMap.put(s, value + 1);
} else {
staticHashMap.put(s, 1);
}
}
line = br.readLine();
}
br.close();
fr.close();
System.out.println(staticHashMap.get(word));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}