프로그램에 나타나는 예외는 나중에 유지 보수에 사용될 수 있습니다! 간단한 테스트를하세요!
코드 사본은 다음과 같습니다.
패키지 helpentity;
import java.io.bufferedReader;
import java.io.file;
import java.io.filereader;
import java.io.filewriter;
import java.io.printwriter;
import java.text.simpledateformat;
import java.util.date;
공개 클래스 로그 {
개인 파일 파일 = null;
공개 파일 getFile () {
반환 파일;
}
public void setfile (파일 파일) {
this.file = 파일;
}
Public Void Savelog (예외 E, String Youname) {
노력하다 {
문자열 nowpath = null;
nowpath = system.getProperty ( "user.dir");
문자열 temppath = null;
this.file = 새 파일 (nowpath);
temppath = this.file.getParent ();
if (temppath == null) {
this.file = 새 파일 (nowpath);
}
this.file = 새 파일 (temppath + "" + file.separator + "log.txt");
인쇄기 작가 = null;
filewriter filewrite = 새로운 filewriter (file, true);
Writer = New Printwriter (Filewrite);
Writer.append (System.GetProperty ( "line.separator")
+ 새로운 simpledateformat ( "yyyy-mm-dd : hh : mm : ss")
.format (새 날짜 ()) + "__" + youname);
Writer.append (System.GetProperty ( "line.separator"));
writer.append ( "***********************************" + e.tostring ()
+ "*****************************");
Writer.append (System.GetProperty ( "line.separator"));
E.printstacktrace (Writer);
Writer.flush ();
Writer.close ();
} catch (예외 e2) {
e2.printstacktrace ();
}
}
}