title: How can I write to an output file?
body: <p>How can I write the bottom section to an output file? It compiles and runs, but shuts down instead of writing it to the file.</p>
  
  <p>I import everything correctly.  But my outfile will not print to TEACHERNAME.out?</p>
  
  <pre><code>import javax.swing.JOptionPane;
  import java.io.FileReader;
  import java.io.PrintWriter;
  import java.util.Scanner;
  import java.io.FileNotFoundException;
  import java.util.Date;
  public class Corpus03
  {
    public static void main(String arg[])
     throws FileNotFoundException
     {
  
     Scanner inputFile = new Scanner(new FileReader("input.txt"));
     PrintWriter outFile = new PrintWriter("TEACHERNAME.out"); 
  
         //INPUT
     name = JOptionPane.showInputDialog("Enter your name: ");
     ID = JOptionPane.showInputDialog("Enter your ID: ");
     str = JOptionPane.showInputDialog("Enter your Annual Salary");
     annualSalary = Double.parseDouble(str);
     //CALCULATIONS
     grossPayPerCheck = annualSalary / 24;
     actualDayWorked = annualSalary / 174;
     perWeek = (annualSalary / 50);
     perHour = perWeek / 40; 
     ssTax = grossPayPerCheck * SS_TAX;
     medTax = grossPayPerCheck * MED_TAX;
     fedTax = grossPayPerCheck * FED_TAX;
     stateTax = grossPayPerCheck * STATE_TAX;
     unitedWay = 20;
     healthIns = 125;
     totalDeductions = ssTax + medTax + fedTax + stateTax + healthIns +    unitedWay;
     netPay = (grossPayPerCheck - totalDeductions);
     Date now = new Date();
     //OUTPUT
     outputStr = "Name: " + name
        + "\r\n" + "Employee ID: " + ID
        + "\r\n" + "Annual Salary: " + String.format("%.2f", annualSalary)
        + "\r\n" + "Gross Pay per Check: $"
        + String.format("%.2f", grossPayPerCheck)
        + "\r\n" + "$" + String.format("%.2f", actualDayWorked) + " per actual day worked"
        + "\r\n" + "$" + String.format("%.2f", perHour) + " per hour"
        + "\r\n\r\n" + "===================="
        + "\r\n" + "DEDUCTIONS PER CHECK"
        + "\r\n" + "===================="
        + "\r\n" + "Social Security Tax: $" 
        + String.format("%.2f", ssTax)
        + "\r\n" + "Medicare Tax: $"
        + String.format("%.2f", medTax)
        + "\r\n" + "Federal Income: $"
        + String.format("%.2f", fedTax)
        + "\r\n" + "State Income Tax: $"
        + String.format("%.2f", stateTax)
        + "\r\n" + "Health Insurance: $125.00"
        + "\r\n" + "United Way Contribution: $20.00"
        + "\r\n\r\n" + "Total Deductions: $" 
        + String.format("%.2f", totalDeductions)
        + "\r\n\r\n" + "Net Pay per check: $" 
        + String.format("%.2f", netPay);
     JOptionPane.showMessageDialog(null, outputStr, 
                       "Teacher Pay Information", 
                     JOptionPane.INFORMATION_MESSAGE);
     outFile.printf("City School Dstric, 111 First Stree, Anytown, OK 12345");
     outFile.println();
     outFile.println();
     outFile.printf("%-40s%-10s\r\n\n", name, ID);
     outFile.close();  
     inputFile.close();
     System.exit(0);
     }
  }
  </code></pre>
  
  <p>The only thing my code doesn't do is write to a separate text file. (Yes, I have more that I need to write to the text file I was just giving an example of some of the things I needed.)   </p>