1 import java.io.OutputStream;
\r
4 public static void main(String[] args)throws Exception{
\r
5 System.out.println("test1");
\r
6 System.setOut(new PrintStream(new myOutputStream(new FileOutputStream("log.txt"),new FileOutputStream("errors.txt"))));
\r
7 System.out.println("test2");
\r
12 class myOutputStream extends OutputStream {
\r
13 static private OutputStream $oos = null;
\r
14 static private OutputStream $fos = null;
\r
15 static private OutputStream $aos = null;
\r
18 public myOutputStream(){
\r
19 if($oos == null)$oos = System.out;
\r
21 public myOutputStream(OutputStream $pfos){
\r
22 if($oos == null)$oos = System.out;
\r
25 public myOutputStream(OutputStream $pfos, OutputStream $paos){
\r
26 if($oos == null)$oos = System.out;
\r
32 public void setFos(OutputStream $pfos)throws IOException{
\r
35 public void setAos(OutputStream $paos)throws IOException{
\r
40 public void close()throws IOException{
\r
42 if($fos != null)$fos.close();
\r
43 if($aos != null)$aos.close();
\r
46 public void flush()throws IOException{
\r
48 if($fos != null)$fos.flush();
\r
49 if($aos != null)$aos.flush();
\r
52 public void write(byte[] $b)throws IOException{
\r
54 if($fos != null)$fos.write($b);
\r
55 if($aos != null)$aos.write($b);
\r
58 public void write(byte[] $b, int $off, int $len)throws IOException{
\r
59 $oos.write($b, $off, $len);
\r
60 if($fos != null)$fos.write($b, $off, $len);
\r
61 if($aos != null)$aos.write($b, $off, $len);
\r
64 public void write(int $b)throws IOException{
\r
66 if($fos != null)$fos.write($b);
\r
67 if($aos != null)$aos.write($b);
\r