Throws IO Exception in method problem.

J

justineee

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top