I have this so far but it only prints the .txt file to the screen:
import java.io.*;
public class ReadFile {
public static void main(String[] args) throws IOException {
String Wordlist;
int Frequency;
File file = new File("file1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
while( (line = br.readLine()) != null) {
String [] tokens = line.split("\\s+");
System.out.println(line);
}
}
}
Can anyone help me so it prints a word list and the words frequency?
Samuel Fernandes
30-Dec-2014public static void main(String[] args) {try {
int totalWords = 0;
TreeMap<String, Integer> freqMap = generateFrequencyList();
for (String key : freqMap.keySet()) {
totalWords += freqMap.get(key);
}
System.out.println("Word\tCount\tPercentage");
for (String key : freqMap.keySet()) {
System.out.println(key+"\t"+freqMap.get(key)+"\t"+((double)freqMap.get(key)*100.0/(double)totalWords));
}
} catch (Exception e) {
e.printStackTrace();
}
}