/* Author : Michael Robinson Program : filesFormatter.java Purpose : This program uses the Formatter class this is a very quick way to create the file called fileone then we write data into into and finally close it. Updated : Jan 29, 2099 */ import java.util.*; public class filesFormatter { //creating a private global variable private static Formatter fileName; public static void createAfile() { try { //make sure this file does NOT exist //otherwise it will overwrite it (delete and re-create) fileName = new Formatter( "fileOne" ); System.out.println( "I have created fileOne" ); } catch(Exception e) { System.out.println( "fileOne was not created ERROR!!" ); } }//end public static void createAfile() public static void writeDataToFile( String fn, String ln, String major) { try { //exactly as using printf //write data into file fileOne fileName.format( "%s %s %s\n", fn, ln, major); System.out.println( "Inserted record : " + fn + " " + ln + " " + major ); } catch(Exception e) { System.out.println( "fileOne was not created ERROR!!" ); } }//end public static void writeDataToFile() public static void closeFile() { fileName.close(); System.out.println( "File has been closed" ); }//end public static void closeFile() public static void main( String arg[] ) { createAfile(); //creates a file //writes the following data to the file writeDataToFile( "Joe", "Smith", "CS" ); writeDataToFile( "Tom", "Richards", "IT" ); writeDataToFile( "Daniel", "Thomason", "Math" ); writeDataToFile( "Robert", "Lambert", "EE" ); writeDataToFile( "Miguel", "Gonzalez", "CS" ); closeFile(); }//end public static void main( String arg[] ) }//end public class filesFormatter