Question: Write a program that asks the user for name of file. The program should display the number of words. my error: Error: cannot find symbol
Write a program that asks the user for name of file. The program should display the number of words.
my error: Error: cannot find symbol symbol: method tocountWord() location: class java.lang.String
import java.io.*; import java.util.Scanner;
public class WordCounter{ public static void main ( String [] args ) { Scanner scanner = new Scanner( System.in ); String userFileName; System.out.println( "Please enter the name of the file you want to read from. Please enter \"count.txt\"" ); userFileName = scanner.nextLine(); File file = new File ( userFileName ); while( !file.exists() ) { System.out.println( userFileName + " does not exists. Please be sure to enter \"count.txt\"" ); userFileName= scanner.nextLine(); file = new File( userFileName ); } Scanner fileToScan = new Scanner( file ); PrintWriter fileToWrite = new PrintWriter( "countToWordCounter.txt" ); while( fileToScan.hasNext() ){ fileToWrite.println( fileToScan.nextLine().tocountWord() ); } System.out.println( " Count has been counted and converted to WordCounter.txt " ); fileToWrite.close(); fileToScan.close(); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
