import java.io.File; import java.io.IOException; import java.io.PrintStream; public class MainClass { public static void main(String[] args) { File file = new File("C:\\temp\\debug.txt"); try { PrintStream ps = new PrintStream(file); System.setOut(ps); } catch (IOException e) { } System.out.println("To File"); } }