Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Is "Public void closeFile()" a problem in the program for AS-Level computing project

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is "Public void closeFile()" a problem in the program for AS-Level computing project

    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... =(
    Last edited by Deep_4; November 8th, 2012 at 01:27 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Is it "public void closeFile()" problem??? (Coding problem)

    Hello muffin. Welcome to the Java Programming Forums

    The problem is with your readRecords() method.

    You are missing a closing }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is it "public void closeFile()" problem??? (Coding problem)

    thankyou very much... =)

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  2. Replies: 2
    Last Post: March 23rd, 2010, 01:38 AM
  3. "While" Problem
    By Killasnipe004 in forum Loops & Control Statements
    Replies: 9
    Last Post: August 13th, 2009, 09:01 AM
  4. Replies: 4
    Last Post: June 18th, 2009, 09:23 AM
  5. [SOLVED] "GridLayout" problem in Java program
    By antitru5t in forum AWT / Java Swing
    Replies: 3
    Last Post: April 16th, 2009, 10:26 AM