excepción no reportada java.io.FileNotFoundException; debe ser atrapado o declarado ser arrojado
Estoy creando una clase, solo una clase, no main () y recibo el error de "excepción no informada java.io.FileNotFoundException; debe capturarse o declararse como arrojada" en esta línea:
FileOutputStream outStr = new FileOutputStream(FILE, true);
No entiendo; Puse un bloque try {} catch {} y sigue informando el error.
Además, también informa un "inicio de tipo ilegal" para el intento y las dos líneas de captura, y también dice que ';' se espera para ambas líneas de captura.
Estoy usando NetBean IDE, FYI.
Gracias por cualquier ayuda
Aquí está el código completo:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileNotFoundException;
public class UseLoggingOutputStream
{
String FILE = "c:\\system.txt";
try
{
FileOutputStream outStr = new FileOutputStream(FILE, true);
}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.getMessage());
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}