Rob Bamforth's Blog
Java, SQL,T-SQL, MySQL, Networking, SQL Server, PHP, COM, DBA, ODBC

Posts Tagged ‘JAVA ReDirect System.out.Println() to file’

JAVA ReDirect System.out.Println() to file

October 21, 2008

Re-directing System output is a simple task. Place the following method in your class:
private void redirectSystemOutput(){
                
         try{
             File file  = new File(“C:/SYSOUT.txt”);
             PrintStream printStream = new PrintStream(new FileOutputStream(file));
             System.setOut(printStream);            
         }catch(Exception e){}         
         
}
 And call the method from the top of your application:
redirectSystemOutput();
 
This will re-direct any instance of System.out.println() to a text file on Root C called SYSOUT.txt.
A [...]