I am trying to redirect the output produced in a Java program into another file("output.txt") located in the same location. I found help on it from here. But when I try the same method I find that my file "output.txt" remains empty. My code looks like this:
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
System.out.println("hello");
Could somebody please point out my mistake here. Thank you in advance for your help.