This class defines a record which is specifically for storing in.

Added on - 13 Sep 2019

  • 2

    pages

  • 410

    words

  • 82

    views

  • 0

    downloads

Showing pages 1 to 1 of 2 pages
This class defines a record which is specifically for storing ina Java random access file. See API of RandomAccessFile class in Java.Attributes:name - String, the max length is 16 charsid - String, the number of digits in id is 4.**/import java.util.*;import java.io.*;public class Record{private String name;private String id;private int NAMELENGTH=16;private int IDLENGTH=4;public Record(){id = " ";name = " ";}public Record(String newId, String newName){id = newId;name = newName;}//Read a 'name' and the related 'id' from the current position of//the given file to the instance variables 'name' and 'id'public void read(RandomAccessFile file) throws IOException{id = readString(file, IDLENGTH);name = readString(file, NAMELENGTH);}//Write the value of 'this' object to the given filepublic void write(RandomAccessFile file) throws IOException{writeStr(file, id, IDLENGTH);writeStr(file, name, NAMELENGTH);}public String getId(){return id;}
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Unlock This Document