How do you get the output of a Java program in a text file instead of getting it on the console?
Created May 8, 2012
pratheesh k p You can get the output into a file instead of the console / command prompt as follows:
System.setOut(new PrintStream(new FileOutputStream("Test.txt")));
System.out.println("Hello How r u");
Now the output Hello How r u will be printed to file instead of command prompt.
System.setOut(new PrintStream(new FileOutputStream("Test.txt")));
System.out.println("Hello How r u");
Now the output Hello How r u will be printed to file instead of command prompt.
In addition, you can also redirect I/O to a file like java aaa > aaa.txt