Friday 24 July 2009

Exception StackTrace to String

How many times have I forgotten this:

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String result = sw.toString();


While we are at it: InputStream to String:

final StringWriter writer = new StringWriter();
IOUtils.copy(urlConnection.getInputStream(), writer);
result = writer.toString();

http://stackoverflow.com/questions/309424/in-java-how-do-a-read-an-input-stream-in-to-a-string

No comments:

Post a Comment