Difficulty throwing exceptions

I think I need to throw IOExceptions and FileNotFoundExceptions to get the following program to work. (It doesn't do much at the moment, just set the stage for some file I/O, but I need to throw the exception to keep going.)

However, the following line:

public static void main(String[] args ) throws IOException {

gives me the following error:

'cannot find symbol. symbol: class IOException location: class fileio.main'

What am I doing wrong? is this not how you throw exceptions?

package fileio;

import java.io.File;

import java.util.Scanner;

import java.io.PrintWriter;

/**

*

* @author David Erb

*/

public class Main {

/** Creates a new instance of Main */

public Main() {

}

/**

* @param args the command line arguments

*/

public static void main(String[] args ) throws IOException {

File MyFile = new File("fnum1.txt");

Scanner MyScanner = new Scanner(MyFile);

PrintWriter MyWriter = new PrintWriter(MyFile);

}

}

[1086 byte] By [Toptomcata] at [2007-11-26 16:20:51]
# 1

import java.io.IOException;

But a better idea wuold be to enclose any code that is doing IO in a try/catch block, and handle any exception you get, even if it is just to print out a stacktrace of the exception for debug purposes.

try {

File MyFile = new File("fnum1.txt");

Scanner MyScanner = new Scanner(MyFile);

PrintWriter MyWriter = new PrintWriter(MyFile);

}

catch (IOException ioe)

{

ioe.printStackTrace();

}

~Tim

Message was edited by:

SomeoneElse

SomeoneElsea at 2007-7-8 22:44:28 > top of Java-index,Java Essentials,New To Java...
# 2

> import java.io.IOException;

>

>

> But a better idea wuold be to enclose any code that

> is doing IO in a try/catch block, and handle any

> exception you get, even if it is just to print out a

> stacktrace of the exception for debug purposes.

>

> ~Tim

Good advice. @OP you would do well to follow what someone else is saying

tjacobs01a at 2007-7-8 22:44:28 > top of Java-index,Java Essentials,New To Java...
# 3
Wow, that was fast. Thanks, that did it.
Toptomcata at 2007-7-8 22:44:28 > top of Java-index,Java Essentials,New To Java...
# 4
SomeoneElse answered your problem, but you might considering just importing all of java.io so you don't need to worry about problems like this:import java.io.*;
Djaunla at 2007-7-8 22:44:28 > top of Java-index,Java Essentials,New To Java...