Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Fixing a program that reads a .txt file java beginner I need help ASAP

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Thanked 0 Times in 0 Posts

    Default Fixing a program that reads a .txt file java beginner I need help ASAP

    I wrote a program to read a .txt file and return how many times a, e, s, and t occur in the .txt file. I am getting an error that I do not know how to fix. It says Error: FileNotFoundException cannot be resolved to a type
    Any help would be appreciated

    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;
    import java.io.BufferedReader;

    public class Count
    public static void main (String[] args) throws FileNotFoundException {

    String phrase; // a string of characters
    int countBlank; // the number of blanks (spaces) in the phrase
    int length; // the length of the phrase
    char ch; // an individual character in the string
    int countA;
    int countE;
    int countS;
    int countT;

    java.io.File file = new java.io.File("counting.txt");
    Scanner inFile = new Scanner (file);

    Scanner scan = new Scanner(System.in);

    phrase = scan.nextLine();
    length = phrase.length();

    // Initialize counts

    while (true)
    if (phrase.equalsIgnoreCase("quit"))



    countBlank = 0;
    countA = 0;
    countE = 0;
    countS = 0;
    countT = 0;

    for ( int i = 0; i < length; i++ )
    if ( phrase.charAt( i ) == ' ' )

    ch = phrase.charAt(i);

    switch (ch)
    case 'a':
    case 'A': countA++;
    case 'e':
    case 'E': countE++;
    case 's':
    case 'S': countS++;
    case 't':
    case 'T': countT++;


    System.out.println ();
    System.out.println ("Number of blank spaces: " + countBlank);
    System.out.println ();

    System.out.println ("Number of A's: " + countA);
    System.out.println ();
    System.out.println ("Number of E's: " + countE);
    System.out.println ();
    System.out.println ("Number of S's: " + countS);
    System.out.println ();
    System.out.println ("Number of T's: " + countT);



  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 697 Times in 679 Posts

    Default Re: Fixing a program that reads a .txt file java beginner I need help ASAP

    Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers. After learning about tags, please edit your post so that your code is readable.

    The FileNotFoundException must be imported just as you've imported other classes.

Similar Threads

  1. Java program that reads a file
    By Rugby_Thompson in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2013, 06:52 AM
  2. Java Program that reads .txt files?
    By bhattia2 in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: November 5th, 2012, 03:30 PM
  3. Write a Java program that reads file
    By Mehwish-S in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 28th, 2012, 03:00 PM
  4. Creating a program that reads from a file
    By Twoacross in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 20th, 2011, 10:19 PM
  5. Beginner Java Program Help/ txt database search
    By JavaConfused in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 21st, 2011, 09:20 AM