如何将printStackTrace存储到字符串中 [英] How to store printStackTrace into a string
本文介绍了如何将printStackTrace存储到字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取 e.printStackTrace()
并将其存储到 String
变量中?我想稍后在程序中使用 e.printStackTrace()
生成的字符串.
How can I get the e.printStackTrace()
and store it into a String
variable?
I want to use the string generated by e.printStackTrace()
later in my program.
我还是Java的新手,所以我对 StringWriter
不太熟悉将是解决方案.或者,如果您有其他任何想法,请告诉我.谢谢
I'm still new to Java so I'm not too familiar with StringWriter
that I think
will be the solution. Or if you have any other ideas please let me know. Thanks
推荐答案
类似
StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
return errors.toString();
应该成为您所需要的.
相关文档:
这篇关于如何将printStackTrace存储到字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文