Hi, I'm pretty new to Java, and I'm really struggling with getting my code to work. The files compile with no errors, but they are supposed to input/output to text files, and I can't get it to output anything. There are two files in the program, the point of it being to count the frequency of words in a text file, and I just wondered if you could tell me where I need to insert the file names to get the code to work correctly. Thank you
FreqListCreator .java
An excerpt from FreqList:
FreqListCreator .java
Code:
import java.io.*;
public class FreqListCreator {
public static void
main(String args[])
throws IOException {
if(args.length != 1) {
System.err.println("usage: FreqListCreator filename");
} else {
FileTokeniser ft = new FileTokeniser(args[0]);
FreqList flist = new FreqList();
while(ft.hasMoreTokens()) {
flist.add(ft.getNextToken());
}
ft.close();
PrintWriter pw = new PrintWriter(new FileWriter(args[0]+".frq"));
flist.save(pw);
pw.close();
}
}
Code:
public void
save(PrintWriter pw) {
Iterator it = storage.keySet().iterator();
while(it.hasNext()) {
String word = (String)it.next();
int freq = getFreq(word);
pw.println(word+" "+freq);
}
}
public static void
main (String args[])
throws IOException {
FreqList flist = new FreqList();
BufferedReader br= new BufferedReader(new FileReader(args[0]));
flist.load(br);
br.close();
Iterator it = flist.iterator();
while(it.hasNext());
String word = (String) it.next();
int freq = flist.getFreq(word);
System.out.println(word+": "+freq);
}
}
Comment