This is a demo program to show the following operations of a

Added on - 18 Sep 2019

  • 2

    Pages

  • 209

    Words

  • 91

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 1 of 2 pages
This is a demo program to show the following operations of a randomaccess file1) Creates a random-access file2) write one record to the file3) read one record from the file*/import java.io.*;import java.io.RandomAccessFile;public class RandomFileApp{public static void main( String args[] ){Record rec = new Record("0002", "Lili Hai");Record rec1 = new Record();RandomAccessFile f = null;try{f = new RandomAccessFile("newfile.txt", "rw");f.seek(0);rec.write(f);}catch (IOException e){System.out.println("cannot write\n" + e);}try{if (f != null){f.seek(0);rec1.read(f);f.close();}}catch (EOFException ee){System.out.println("end of file");}catch (IOException e){System.out.println("cannot read\n" + e);}System.out.println(rec1);} // end main} // end class RandomFile
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document