#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Scanner ask for and read file


    Error:
    exception FileNotFoundException is never thrown in body of corresponding try statement

    import java.util.Scanner;
    import java.io.*;

    public class StringMenu {
    public static void main(String[] args) {
    try {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter filename: ");
    String filename = in.nextLine();

    }
    catch (FileNotFoundException e)
    {
    System.out.println ("File not found!");
    System.exit (0);
    }

    }
    }
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Thread moved to Java forum.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,023
    Rep Power
    1285
    You cannot create a catch block for an exception for a checked exception unless there is code in the corresponding try block that has the potential to throw that exception.

IMN logo majestic logo threadwatch logo seochat tools logo