This is a demo program to show the following operations of a
2 Pages209 Words154 Views
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
Found this document preview useful?
Related Documents
Code for Proxy Cache Assignment - Deskliblg...
|7
|1720
|105
Design and Develop an Assemblerlg...
|6
|805
|84
CS4348 - Operating Systems Conceptslg...
|5
|1324
|177
R programming for analyzing flight dataset and flight schedulinglg...
|26
|1439
|140
This class defines a record which is specifically for storing in.lg...
|2
|410
|256
Memory Sequence Game - Java Program for Console Based Gamelg...