Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void countWords()throws IOException
- {
- FileReader fr = new FileReader (file); //File reader object to read file
- BufferedReader br = new BufferedReader (fr); //Reads text from a character-input stream
- String line = br.readLine(); //Store each line as a string,so we can iterate through the text file
- while (line != null) //While there is a line
- {
- String []parts = line.split(" "); // parse the strings between the spaces
- for( String word : parts) //Loop through array of words using an enhanced for loop
- {
- if(isNumeric(word)!=true && isValidWord(word)==true) // Lets check if the string is not a number and is a valid word
- {
- count++; // Count the words
- }
- }
- line = br.readLine(); //Read the next line
- }
- br.close(); // Close the text file
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement