=====Rediriger la sortie standard vers une variable String===== // Create a stream to hold the output ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); // IMPORTANT: Save the old System.out! PrintStream old = System.out; // Tell Java to use your special stream System.setOut(ps); // Print some output: goes to your special stream System.out.println("Foofoofoo!"); // Put things back System.out.flush(); System.setOut(old); // Show what happened System.out.println("Here: " + baos.toString()); [[http://stackoverflow.com/questions/8708342/redirect-console-output-to-string-in-java|Redirect console output to string in java - Stack Overflow]] {{ :lang:java:console:redirect_console_output_to_string_in_java_-_stack_overflow_2020-04-29_10_17_33_pm_.html |Archive du 03/01/2012 le 29/04/2020}}