title: How to outprint result to txt file?
body: <p>I try to print out all the pr.prinln(on the bottom of the code) to the result.txt as it show on screen, However; as I run the code the result.txt is generated but remains empty in the body. Please help! </p>
  
  <pre><code>import java.io.*;
  public class Assignment8
   {
  public static void main(String[] args)
  {
  try {
  //create an InputStreamReader obj first
  InputStreamReader ir = new InputStreamReader(System.in);
  File outf=new File("result.txt");
  PrintWriter pr = new PrintWriter(outf);
  
  //create a BufferedReader obj
  BufferedReader br = new BufferedReader(ir);
  
  //variales
  double b,a,d,w, interest;
  int count =0;
  double sumd =0.00;
  double sumw =0.00;
  double sumi =0.00;
  double totalI;//format
  
  System.out.print("\nEnter the starting balance on the account: $");
  b = Double.parseDouble(br.readLine());
  
  System.out.print("\nEnter the annual interest rate on the account (e.g. .04): ");
  a = Double.parseDouble(br.readLine());
  
  for(int i=1; i&lt;4; i++)
  {
      count++;
  
      //#3 read in the next data
      System.out.print("\nMonth"+i);
      System.out.print("\nTotal deposits for this month: $");
          d = Double.parseDouble(br.readLine());
          sumd += d;
      System.out.print("Total withdrawals for this month: $");
          w = Double.parseDouble(br.readLine());
          sumw += w;
          interest = b+(b+d-w)*a/12-b;
          sumi +=interest;
  
  }
  totalI=+b+sumd-sumw+sumi;
  
  System.out.println("\nQuarterly Savings Account Statement");
  System.out.println("\nStarting balance:    $ "+b);
  System.out.println("Total deposits:    + $ "+sumd);
  System.out.println("Total withdrawals: - $ "+sumw);
  System.out.println("Total interest:    + $   "+sumi);
  System.out.println(" ----------- ");
  System.out.println("Ending balance:      $ "+totalI);
  
  
  pr.println("\nQuarterly Savings Account Statement");
  pr.println("\nStarting balance:    $ "+b);
  pr.println("Total deposits:    + $ "+sumd);
  pr.println("Total withdrawals: - $ "+sumw);
  pr.println("Total interest:    + $   "+sumi);
  pr.println(" ----------- ");
  pr.println("Ending balance:      $ "+totalI);
  
  //double d = 3.14159;
  //printf ("%.2f", d);
  
  }
  catch (IOException e)
  {
  System.out.println(e);
  }
  catch (ArithmeticException e)
  {
      System.out.println("Wrong, restart!");
  }
  }
  </code></pre>
  
  <p>}</p>