Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Throws IO Exception in method problem.

Reply
Thread Tools

Throws IO Exception in method problem.

 
 
justineee
Guest
Posts: n/a
 
      10-29-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is an exception specification needed if the method throws and catchesits own exception? elcapitan666@gmail.com C++ 2 11-27-2007 04:01 AM
Do you need finally when your method throws Exception.. Tomas Java 17 10-05-2005 10:40 AM
when to throws or catch exception in chains of method calls? Matt Java 2 07-01-2004 02:27 PM
Exception Exception is not compatible with throws clause in Runnable.run() Chris Miller Java 4 11-22-2003 03:11 PM
Re: Mapi Attachment method WriteToFile throws exception ... Peter Curran Python 1 06-24-2003 08:34 PM



Advertisments