How to redirect the output of an interactive program to a file?
<p>I have an interactive java program which takes input from user...now i need to redirect whatever output that has been printed on the screen to a file? Is is possible.</p>

<p>From the java docs I got the method "System.setOut(PrintStream ps);" but i am not getting as to how to use this method?</p>

<p>E.g. I have  a program as:</p>

<pre><code>public class A{
  int i;
   void func()
   {
      System.out.println("Enter a value:");
      Scanner in1=new Scanner(System.in);
      i= in1.nextInt();
      System.out.println("i="+i);
   }
 }
</code></pre>

<p>Now i want to redirect the output given below to a file:</p>

<pre><code> Enter a value:
 1
 i=1
</code></pre>
