Поймать исключения, которые появляются в программе, можно использовать для последующего обслуживания! Сделайте простой тест!
Кода -копия выглядит следующим образом:
Справочник по упаковке;
Импорт java.io.bufferedReader;
Импорт java.io.file;
Импорт java.io.filereader;
Импорт java.io.fileWriter;
Импорт java.io.printwriter;
импортировать java.text.simpledateformat;
импортировать java.util.date;
открытый класс журнал {
private file file = null;
public file getFile () {
вернуть файл;
}
public void setFile (файл файла) {
this.file = file;
}
Public void Savelog (Exception E, String Youname) {
пытаться {
String nowpath = null;
nowpath = System.getProperty ("user.dir");
String Temppath = null;
this.file = новый файл (nowpath);
temppath = this.file.getParent ();
if (temppath == null) {
this.file = новый файл (nowpath);
}
this.file = новый файл (temppath + "" + file.separator + "log.txt");
PrintWriter Writer = null;
FileWriter fileWrite = new FileWriter (файл, true);
writer = new PrintWriter (файл while);
writer.append (System.getProperty ("line.separator")
+ new 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 (писатель);
writer.flush ();
writer.close ();
} catch (Exception e2) {
e2.printstacktrace ();
}
}
}