Is there a way to retrieve output from the console that has been outputted by:
System.out.print("blabla");
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to be able to see what you already wrote to the console, you need to write your own
PrintStreamimplementation that simply wraps an existingPrintStream, stores whatever it is supposed to write and then delegates (all the methods) to the wrapped (original)PrintStreamto do the actual job. How you store the messages entirely depends on your needs (store only the last written String, store a map of timestamp -> String or whatever). Once you have this, you can replaceSystem.outwith your own implementation (viaSystem.setOut()):You also may need to take care of thread-safety (StringBuffer is thread-safe, but you may need more than this).
Once you have the above, you can:
EDIT: added the
println()implementations using a platform-independentnewLine.