Ask a question from expert

Ask now

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

2 Pages209 Words154 Views
   

Added on  2019-09-18

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

   Added on 2019-09-18

BookmarkShareRelated Documents
This is a demo program to show the following operations of a random access file 1) Creates a random-access file 2) write one record to the file 3) 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
This is a demo program to show the following operations of a_1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Code for Proxy Cache Assignment - Desklib
|7
|1720
|105

Design and Develop an Assembler
|6
|805
|84

CS4348 - Operating Systems Concepts
|5
|1324
|177

R programming for analyzing flight dataset and flight scheduling
|26
|1439
|140

This class defines a record which is specifically for storing in.
|2
|410
|256

Memory Sequence Game - Java Program for Console Based Game
|8
|998
|259