i'm trying to create a program that asks the user to input a file (but the file name is standard name that will not change) and input a specific character. The program will use looping to find how many of that specific character is in the .txt file. This is the coding I have and an error message comes up after the user input prompts come up.
import java.util.Scanner;
import java.io.*;
public class Assn3Prog1
{
public static void main(String[] args) throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a filename: ");
String filename = keyboard.nextLine();
System.out.print("Enter a character: ");
String character = keyboard.nextLine();
char answerChar = Character.toLowerCase(character.charAt(0));
File file = new File("File.txt");
Scanner inputFile = new Scanner(file);
long max = file.length();
int numCharacters = 0;
character = inputFile.nextLine();
for (int i = 0; i < max; ++i)
{char randomChar = Character.toLowerCase(filename.charAt(i));
if (answerChar == randomChar)
++numCharacters;}
System.out.println("Found " + numCharacters + " of those characters in the file.");
inputFile.close();
}}