Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trying to read a file, and it gives me "java.io.IOException"

807597Feb 19 2005 — edited Feb 19 2005
I'm writing a little swing text editor for my first java project, and the open method is like this:


public void openFile() throws IOException {

JFileChooser chooseOpen = new JFileChooser();
chooseOpen.showOpenDialog(null);

File openFile = chooseOpen.getSelectedFile();

FileReader in = new FileReader(openFile);
BufferedReader br = new BufferedReader(in);

String fileText = br.readLine();
output.setText(fileText);


}

It seems like it should work fine to me, you choose a file, and it opens it, then outputs it to my textArea. I even have it throwing IOException. Why is it giving me that message then? (this is the only method I'm having a problem with.)

the full error message is:

unreported exception java.io.IOException; must be caught og declared to be thrown
openFile();
^
1 error

thanks,
alex
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2005
Added on Feb 19 2005
1 comment
3,741 views