當前位置:編程學習大全網 - 腳本源碼 - 怎麽獲取e.printStackTrace的內容並記錄到log4j日誌中

怎麽獲取e.printStackTrace的內容並記錄到log4j日誌中

源代碼如下:已測試成功

import java.io.*;

public class ThrowableTest extends FileNotFoundException {

public static void main(String argv[]) {

try {

FileInputStream f = new FileInputStream("D:\\test.txt");

} catch (FileNotFoundException e) {

try {

PrintWriter p = new PrintWriter(new FileOutputStream("D:\\errors.txt"));

p.println("=== toString() ===");

p.println(e.toString()+"\n");

p.println("=== getLocalizedMessage() ===");

p.println(e.getLocalizedMessage());

p.println("=== getMessage() ===\n");

p.println(e.getMessage());

p.println("=== printStackTrace() ===");

e.printStackTrace(p);

p.flush();

} catch (IOException e1) {

e1.printStackTrace();

}

}

}

}

  • 上一篇:《同壹屋檐下》李行是演員嗎?
  • 下一篇:父親節畫怎麽畫簡單又好看
  • copyright 2024編程學習大全網