tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(追記) の変更点


[[tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(2 of 2)]]

#navi(../)

* Throwable printStackTrace() の結果を文字列として取り出す(追記) [#n12ec0ad]


以前書いた

> [[tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(1 of 2)]]~
[[tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(2 of 2)]]

について、PipedReader/Writer を用いて実現しようとしていましたが、
もっと簡便な方法がありました。。。

Throwable#printStackTrace(PrintWriter) の引数に渡す PrintWriter に
StringWriter を使えばよいようです。
StringWriter なんて便利なクラスがあったんですね。。。

ちなみにマルチスレッドでの挙動は確認していません。