import java.io.EOFException; import java.io.IOException; import java.io.RandomAccessFile; public class ReadRandomFile { private RandomAccessFile input; //enable user to select file to open public void openFile() { try //open file { input = new RandomAccessFile( "marking.dat", "r" ); }//end try catch (IOException ioException) { System.err.println("File does not exist."); }//end catch }//end method openFile //read and display records public void readRecords() { RandomAccessMarkingRecord record = new RandomAccessMarkingRecord(); System.out.printf ( "%-10s %-10s %-15s %-15s %15s \n", "Id Number", "First Name", "Last Name", "Exam Mark", "Assessment" ); try //read a record and display { while(true) { do { record.read(input); }while ( record.getAccount() == 0); //display record contents System.out.printf("%-10s %-12s %-12s %10d %10d \n", record.getIdNumber(), record.getFirstName(), record.getLastName(), record.getExamMark(), record.getAssessment() ); }//end while }//end try catch (EOFException eofException )//close file { return; //end of file was reached }//end catch catch(IOException ioException) { System.err.println( "Error reading file." ); System.exit(1); }//end catch }//end method readRecords //close file and terminate application public void closeFile() { try //close file and exit { if ( input != null ) input.close(); }//end try catch(IOException ioException) { System.err.println("Error closing file."); System.exit(1); }//end catch }//end method closeFile }//end class ReadRandomFile
***Help me A.S.A.P... This is for my AS-Level Computing Project... =(