Writing to file
I want to write some data to an ASCII file. I currently have a large output algorithm, that displays data on the screen, and I was wondering if there was a way that I could modify my code so that everything that is displayed on the screen throughout certain parts of my program is also written to a file.
Like, could I get a specific method to run it's print commands on the screen and also write the same data to a file?
[435 byte] By [
imdandmana] at [2007-11-27 5:25:59]

Method System.setOut lets you redirect System.out. You could easily define an OutputStream subclass that pumps to several target streams:
public class PumpStream extends OutputStream {
private OutputStream out1, out2; //how about a list?
public PumpStream(OutputStream out1, OutputStream out2) {
this.out1 = out1;
this.out2 = out2;
}
public void write(byte[] b) throws IOException {
out1.write(b);
out2.write(b);
}
...
}