Avresti potuto fare anche così:
L'unica cosa se definisci che il metodo Weditor(String nomefile) può sollevare l'eccezione FileNotFoundException puoi anche non gestirla all'interno del metodo stessoCodice PHP:class Weditor {
StringBuffer $_buffer_ = new StringBuffer();
int $_curPos_ = 0;
/** ----------------------------------------------- **/
public Weditor(String nomefile) throws FileNotFoundException {
File f = new File(nomefile);
int ch;
try{
if(f.exists())
{
FileInputStream fis = new FileInputStream(nomefile);
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
Reader in = new BufferedReader(isr);
while ((ch = in.read()) > -1) {
$_buffer_.append((char)ch);
}
in.close();
} else {
throw new FileNotFoundException("File non trovato.");
}
}
catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
catch( IOException io ){
io.printStackTrace();
}
}
}

Rispondi quotando