Throws IO Exception in method problem.

Discussion in 'Java' started by justineee, Oct 29, 2008.

  1. justineee

    justineee Guest

    Hi Everyone,

    I want this readfile method to be called in my other class but the
    problem is the "throws IO Exception" code..
    It says in the other class that "unreported exception
    java.io.IOException; must be caught or declared to be thrown"

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


    public class ReadFile
    {
    public void loadFile()
    throws IOException
    {
    int nWords = 0;
    FileReader f = new FileReader ("initlist.txt");
    Scanner input = new Scanner ( f );
    while (input.hasNextLine())
    {
    String line = input.nextLine();
    System.out.println(line);
    nWords++;
    }
    }
    }

    How will I fix this?? Thanks


    Justine
     
    justineee, Oct 29, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Miller
    Replies:
    4
    Views:
    13,373
    Chris Smith
    Nov 22, 2003
  2. Matt
    Replies:
    2
    Views:
    473
    Chris Smith
    Jul 1, 2004
  3. Tomas
    Replies:
    17
    Views:
    2,873
    steve
    Oct 5, 2005
  4. Peter Curran
    Replies:
    1
    Views:
    3,816
    Rudy Schockaert
    Jun 24, 2003
  5. Replies:
    2
    Views:
    336
Loading...

Share This Page