기타/Java

[Java] 예외 메시지 log파일에 출력하기 - (1)

words 2010. 7. 19. 18:39
log파일은 단순한 파일일 뿐 특별한 의미를 지니는 확장자는 아니다.

class ExceptionEx {
   public static void main(String args[]){
      
      PrintStream ps = null;
      
      try {
         ps = new PrintStream("error.log");
         
         System.out.println(1);
         System.out.println(2);
         System.out.println(3);
         System.out.println(0/0);
         System.out.println(4);
      } catch (Exception ee) {
         ee.printStackTrace(ps);
        
ps.println("예외메시지 : " + ee.getMessage());
      }
   }
}

 error.log파일에 에러 정보가 저장된다.

참조 : 자바의 정석