I am working on a program where the user creates a file, enters a certain character in the program, and the program displays the entered character from the file and how many times it is written in the file. Any kind of push or help would be extremely appreciated. Everything with the program is working fine, except the while(fileScan.hasNext()) {}, I am needing some help figuring this out.
import java.util.Scanner; import java.io.*; public class FileLetterCounter { public static void main(String[] args) throws IOException { // declare variables String fileName; int times; String letter; Scanner nameScan = new Scanner(System.in); // getting the name of the file. System.out.print("Enter the name of the file: "); fileName = nameScan.nextLine(); // getting the letter the file will read System.out.print("Enter the letter for the file to search: "); letter = nameScan.nextLine(); // open the file File file = new File(fileName); Scanner fileScan = new Scanner(file); // reading the file while(fileScan.hasNext()) { } // close file fileScan.close(); // display information System.out.println("The file contains \'" + letter + "\' " + times + " time(s)."); } }