2009-02-19 7 views

Répondre

25

Vous ne pouvez pas faire cela exactement, puisque StringWriter est un Writer, pas un Stream. Mais vous pouvez le faire:

// 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 - plus supprimé mon doublon – toolkit

Questions connexes