/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package readtextfiletest; import java.io.File; import java.io.FileNotFoundException; import java.lang.IllegalStateException; import java.util.NoSuchElementException; import java.util.Formatter; /** * * @author jcmtiernan */ public class WriteTextFile { private Formatter output; public void openFile() { try { output = new Formatter( new File( "clientdata.txt" ) ); } // end try catch ( FileNotFoundException fileNotFoundException ) { System.err.println( "Error opening file." ); System.exit( 1 ); } // end catch } // end method openFile public boolean writeRecord(AccountRecord record) { /* output.format("%-10d,%-12s,%-12s,%10.2f\n", record.getAccount(), record.getFirstName(), record.getLastName(), record.getBalance()); */ output.format(record.getAccount()+ ", "+ record.getLastName()+", "+ record.getFirstName()+", "+record.getBalance()+"\n"); return true; } // close file and terminate application public void closeFile() { if ( output != null ) output.close(); // close file } // end method closeFile }