Is it possible to read the contents from a printstream??
I’m trying to capture the text from the console, in a midp game, to show a “console” in the phone with the contents of the system.err and system.out contents and i have ran out of ideas :
Is it possible to read the contents from a printstream??
I’m trying to capture the text from the console, in a midp game, to show a “console” in the phone with the contents of the system.err and system.out contents and i have ran out of ideas :
Can you use System.out = new MyPrintStream(); ?
Where your stream implementation is setup to dump the output into your console?
Kev
System.out, err and in are final. You can change them with System.setOut() etc. if the security manager allows it.
I’ve attached a class (LoggerPrintStream) that I made for directing System.err to both console and file with nice timestamps. Here is the code for using it:
try {
String message = "\n\n----- " + APP_NAME + " " + APP_VERSION
+ " started on " + new Date().toString() + " -----";
PrintStream logger = new LoggerPrintStream(new FileOutputStream(DEBUG_LOG_FILE, true), System.err, message);
System.setErr(logger);
} catch (FileNotFoundException e) {
System.err.println("Unable to write to: " + DEBUG_LOG_FILE);
}
Thanks ;D I’ll try to implement my own printstream
Nice code Jackal ^^