Friday, June 29, 2012

Redirecting the output of System.out.println()

Hi Guys,

Using the below example we can redirect the out put of the System.out.println().

public class ChangeOut {
  public static void main(String args[]) {
    try {
      System.setOut(new PrintStream(new FileOutputStream("log.txt")));
      System.out.println("Now the output is redirected!");
    } catch(Exception e) {}
  }
}

Thanks

Rajesh Kumar yuvaraj

No comments:

Post a Comment