Catching exceções que aparecem no programa podem ser usadas para manutenção posterior! Faça um teste simples!
A cópia do código é a seguinte:
HelpEntity do pacote;
importar java.io.bufferedReader;
importar java.io.file;
importar java.io.fileReader;
importar java.io.filewriter;
importar java.io.printwriter;
importar java.text.simpledateFormat;
importar java.util.date;
classe pública log {
arquivo de arquivo privado = nulo;
public arquivo getfile () {
arquivo de retorno;
}
public void setFile (arquivo de arquivo) {
this.File = arquivo;
}
public void savelog (Exceção e, string youname) {
tentar {
String agorapath = null;
agoraPath = System.getProperty ("user.dir");
String temppath = null;
this.File = novo arquivo (agoraPath);
temppath = this.file.getParent ();
if (temppath == null) {
this.File = novo arquivo (agoraPath);
}
this.file = novo arquivo (temppath + "" + file.separator + "log.txt");
PrintWriter Writer = NULL;
FileWriter fileWrite = new FileWriter (File, true);
writer = new PrintWriter (FileWrite);
writer.append (System.getProperty ("line.separator")
+ novo SimpleDateFormat ("yyyy-mm-dd: hh: mm: ss")
.Format (new Date ()) + "__" + Youname);
writer.append (System.getProperty ("line.separator"));
writer.append ("******************************" + E.ToString ()
+ "*********************************");
writer.append (System.getProperty ("line.separator"));
E.PrintStackTrace (escritor);
writer.flush ();
writer.close ();
} catch (Exceção E2) {
e2.PrintStackTrace ();
}
}
}