2009-02-19 18 views

Respuesta

25

No se puede hacer eso exactamente, ya que StringWriter es Writer, no Stream. Pero puede hacer esto:

// create a ByteArray stream, which will be wrapped by a PrintStream 
ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
PrintStream ps = new PrintStream(baos); 
System.setOut(ps); 

// print whatever you got 
String result = baos.toString(); 
+1

+1 - más eliminado mi publicación duplicada – toolkit

Cuestiones relacionadas