/* Author : Michael Robinson Program : filesLargeSize.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. ************** WARNING ****************** this program will produce a text file of size close to three gigabytes Updated : Jan 29, 2099 */ import java.util.*; import java.io.*; import java.text.DecimalFormat; public class filesLargeSize { //create the public global object recordsFormat of class DecimalFormat public static DecimalFormat recordsFormat = new DecimalFormat( " #,###" ); public static void writeFile() { System.out.println( "\n Writting records into the text LargeFile" ); try { //creates the bufferedWrite object of BufferedWriter class to write data //into the LargeFile text file. This class allows us to write very large //files limited by the storage available BufferedWriter bufferedWrite = new BufferedWriter( new FileWriter( "LargeFile") ); String record = "Java uses the File class in java.io.File"; int x = 0; while( x < 69999999 ) { bufferedWrite.write( record + "\n" ); //write record to file x++; } bufferedWrite.close(); System.out.println( "\n Records written = " + recordsFormat.format(x) ); } catch( Exception e ) { e.printStackTrace(); } }//end public static void writeFile() public static void readFile() { System.out.println( "\n Reading records from the text LargeFile" ); try { //creates the bufferedReader object of BufferedReader class to read data from the //LargeFile text file. This class allows us to read from very large files BufferedReader bufferedReader = new BufferedReader( new FileReader( "LargeFile") ); String record = bufferedReader.readLine(); //read record from file int x = 1; while( record != null ) { record = bufferedReader.readLine(); //read record from file x++; } bufferedReader.close(); System.out.println( " Records read = " + recordsFormat.format(x-1) + "\n\n"); } catch( Exception e ) { e.printStackTrace(); } }//end public static void readFile() public static void main( String args[] ) { Scanner kb = new Scanner( System.in ); System.out.println( "\n\n\n************** WARNING ******************" ); System.out.println( " this program will produce a text file" ); System.out.println( " of size close to three gigabytes" ); System.out.print( "\n Do you want to continue (Y/N): " ); //read the keyboard and assign value entered to the keyboard String variable String keyboard = kb.nextLine(); //extract the first character of the keyboard String and assign it to the String letter String letter = keyboard.substring(0,1).toUpperCase(); //displays the distance from Y's ASCII code. 0 means that the letter entered was Y System.out.println( "\n ASCII distance from Y to " + letter + " = " + letter.compareTo( "Y" ) ); if( letter.compareTo( "Y" ) != 0 ) { System.out.print( "\n I received " + letter + " Exiting program, Thank You\n\n\n" ); System.exit(0); //exit/terminate this program at this point } writeFile(); //call this method readFile(); //call this method }//end public static void main( String args[] ) }//end public class filesLargeSize