Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.setOut(new PrintStream(new FileOutputStream("system_out.txt")));
    System.out.println("sent to the file system_out.txt");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    System.setOut(new LogStream(System.out, new PrintStream(new FileOutputStream("out.log"))));
    System.setErr(new LogStream(System.err, new PrintStream(new FileOutputStream("err.log"))));

    System.out.println("output");
    System.err.println("error");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("output.dat"))));

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    FileOutputStream f = new FileOutputStream("file.txt");

    System.setOut(new PrintStream(f));

    System.out.println("This is from java2s.com");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:\\a.txt");
    PrintStream ps = new PrintStream(file);
    System.setOut(ps);
    System.out.println("To File");
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:\\temp\\debug.txt");
    try {/*  w w w.j  a va2  s  . c om*/
        PrintStream ps = new PrintStream(file);
        System.setOut(ps);
    } catch (IOException e) {
    }
    System.out.println("To File");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File outFile = new File("stdout.txt");
    PrintStream ps = new PrintStream(new FileOutputStream(outFile));

    System.out.println(outFile.getAbsolutePath());

    System.setOut(ps);

    System.out.println("Hello world!");
    System.out.println("Java I/O  is cool!");
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);//from w  w  w.  jav a  2 s .  c om
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close();
    System.setOut(console);
}

From source file:Redirect.java

public static void main(String args[]) throws Exception {
    PrintStream origOut = System.out;
    PrintStream origErr = System.err;

    InputStream stdin = null;//  w  w  w . ja  va 2s  .c o  m
    stdin = new FileInputStream("Redirect.in");
    PrintStream stdout = null;
    stdout = new PrintStream(new FileOutputStream("Redirect.out"));
    PrintStream stderr = null;
    stderr = new PrintStream(new FileOutputStream("Redirect.err"));
    origOut.println("1");
    System.out.println("2");
    origOut.println("3");
    System.err.println("4");
    origErr.println("5");

    System.setIn(stdin);
    System.setOut(stdout);
    System.setErr(stderr);

    origOut.println("\nR");
    System.out.println("T");
    origOut.println("Tq");
    System.err.println("Tqw");
    origErr.println("Test");

    origOut.println("\nRedirect:  Round #3");
    int inChar = 0;
    while (-1 != inChar) {
        try {
            inChar = System.in.read();
        } catch (Exception e) {
            // Clean up the output and bail.
            origOut.print("\n");
            break;
        }
        origOut.write(inChar);
    }

    stdin.close();
    stdout.close();
    stderr.close();

    System.exit(0);
}

From source file:Redirecting.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);//w ww  .jav  a2  s.  c o m
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close(); // Remember this!
    System.setOut(console);
}