Java IO error
I am a newie in java IO encountering an odd error, my platform is osx tiger, java 1.5.
and program fragment is:
import java.io.*;
....
public static void main(String[] args) {
byte[] b = {50, 50, 51, 32};
System.out.write(b);
System.out.println();
}
When compile it, get "unreported exception javaio.IOException; must be caught or declared to be thrown
System.out.write(b) "
If I catch the IOException and rewrite it as:
try {System.out.write(b)}
catch (IOException e) {System.err.println(e) }
The above error is fixed. But if I rewrite "System.out.write(b)" as
"System.out.write(b, 2, 1)" getting a compile-time error again:
"exception java.io.IOException is never thrown in body of corresponding try statement
catch(IOException e) {System.err.println(e)} "
At this stage, when remove the catch statement, compile-time error is fixed again. Can anyone tell me why? thx.
|