public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
System.setOut( out );
System.setErr(err);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]); //
}
* This source code was highlighted with Source Code Highlighter .
public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
System.setOut( out );
System.setErr(err);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]); //
}
* This source code was highlighted with Source Code Highlighter .
public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
System.setOut( out );
System.setErr(err);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]); //
}
* This source code was highlighted with Source Code Highlighter .
Hello!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at systemout.Main.main (Main.java:38)
public class DualStream extends PrintStream {
PrintStream out ;
public DualStream(PrintStream out1, PrintStream out2) {
super(out1);
this . out = out2;
}
public void write( byte buf[], int off, int len) {
try {
super.write(buf, off, len);
out .write(buf, off, len);
} catch (Exception e) {
e.printStackTrace();
}
}
public void flush() {
super.flush();
out .flush();
}
}
* This source code was highlighted with Source Code Highlighter .
public class DualStream extends PrintStream {
PrintStream out ;
public DualStream(PrintStream out1, PrintStream out2) {
super(out1);
this . out = out2;
}
public void write( byte buf[], int off, int len) {
try {
super.write(buf, off, len);
out .write(buf, off, len);
} catch (Exception e) {
e.printStackTrace();
}
}
public void flush() {
super.flush();
out .flush();
}
}
* This source code was highlighted with Source Code Highlighter .
public class DualStream extends PrintStream {
PrintStream out ;
public DualStream(PrintStream out1, PrintStream out2) {
super(out1);
this . out = out2;
}
public void write( byte buf[], int off, int len) {
try {
super.write(buf, off, len);
out .write(buf, off, len);
} catch (Exception e) {
e.printStackTrace();
}
}
public void flush() {
super.flush();
out .flush();
}
}
* This source code was highlighted with Source Code Highlighter .
public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream dual = new DualStream(System. out , out );
System.setOut(dual);
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
dual= new DualStream(System.err, err);
System.setErr(dual);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]);
}
* This source code was highlighted with Source Code Highlighter .
public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream dual = new DualStream(System. out , out );
System.setOut(dual);
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
dual= new DualStream(System.err, err);
System.setErr(dual);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]);
}
* This source code was highlighted with Source Code Highlighter .
public static void main( String [] args) throws FileNotFoundException {
PrintStream out = new PrintStream( new FileOutputStream( "out.log" ));
PrintStream dual = new DualStream(System. out , out );
System.setOut(dual);
PrintStream err = new PrintStream( new FileOutputStream( "err.log" ));
dual= new DualStream(System.err, err);
System.setErr(dual);
System. out .println( "Hello!" );
String [] array = { "1" , "2" , "3" };
System. out .println(array[5]);
}
* This source code was highlighted with Source Code Highlighter .
Hello!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at systemout.Main.main (Main.java:38)
Hello!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at systemout.Main.main (Main.java:38)
Source: https://habr.com/ru/post/47109/
All Articles