Weird IOException's

Okay people I hope you can help me out.

This is my program code:

public static void main (String args[]) {

try {

FileOutputStream out = new FileOutputStream("c:\\output.txt");

ObjectOutputStream s = new ObjectOutputStream(out);

s.writeObject("Today");

Song song = new Song("lalala", "lala",1);

s.writeObject(song);

s.flush();

}

catch (Exception e) {

System.out.println("mis");

e.printStackTrace();

}

}

When I execute this program, nothing is written to the c:\\index.txt file. And when I remove the 'try' and 'catch' statements, I get the following error:

unreported exception java.io.FileNotFoundException; must be caugth or declared to be thrown. FileOutputStream out = new FileOutputStream("c:\\output.txt");

I hope someone can help me out.

By the way, I'm programming Java in Windows XP.

[917 byte] By [PeterKoka] at [2007-9-28 3:24:47]
# 1

>

> When I execute this program, nothing is written to the

> c:\\index.txt file. And when I remove the 'try' and

> 'catch' statements, I get the following error:

>

Your code says 'output.txt' but I presume you knew that.

Instead of "catch(Exception e)" use "catch(Throwable e)"

jschella at 2007-7-7 22:57:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Make sure the class Song implements Serializable interface.
psajbha at 2007-7-7 22:57:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

You should close the streams...

s.close();

out.close();

> When I execute this program, nothing is written to the

> c:\\index.txt file. And when I remove the 'try' and

> 'catch' statements, I get the following error:

>

> unreported exception java.io.FileNotFoundException;

> must be caugth or declared to be thrown.

> FileOutputStream out = new

> FileOutputStream("c:\\output.txt");

this is absolutely normal --> IOException is a checked exception an you need to catch it; otherwise the compiler will produce the above error.

juchlia at 2007-7-7 22:57:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
try {FileOutputStream out = new FileOutputStream("c:\\output.txt");}catch(java.io.FileNotFoundException e){}
dvohra09a at 2007-7-7 22:57:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...