相关疑难解决方法(0)

如何将printStackTrace()中的异常写入Java中的文本文件?

我需要在Java中的文本文件中捕获异常.例如:

try {
  File f = new File("");
}
catch(FileNotFoundException f) {
  f.printStackTrace();  // instead of printing into console it should write into a text file    
  writePrintStackTrace(f.getMessage()); // this is my own method where I store f.getMessage() into a text file.
}
Run Code Online (Sandbox Code Playgroud)

使用getMessage()作品,但它只显示错误消息.我想要printStackTrace()包含行号的所有信息.

java exception

24
推荐指数
2
解决办法
4万
查看次数

标签 统计

exception ×1

java ×1