I am making a program that makes an user choose a file then the program reads from the file. Now I've been told to make the program using bufferedreader and string tokenizer. So far I got program opening the file and counting the number of lines. But the number of words is not so easy.
This is my code so far:
int getWords() throws IOException
{
int count = 0;
BufferedReader BF = new BufferedReader(new FileReader(f));
try {
StringTokenizer words = new StringTokenizer(BF.readLine());
while(words.hasMoreTokens())
{
count++;
words.nextToken();
}
BF.close();
} catch(FileNotFoundException e) {
}
return count;
}
Buffered reader can only read a line at a time but I don't know how to make it read more lines.