Ask a question from expert

Ask now

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

2 Pages410 Words256 Views
   

Added on  2019-09-13

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

   Added on 2019-09-13

BookmarkShareRelated Documents
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;}
This class defines a record which is specifically for storing in._1

End of preview

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

Related Documents
Program Description | Document
|15
|1603
|24

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

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

NAME:SHRAVAN S REGISTRATION NUMBER:19BCE2548 1)Write your
|3
|394
|35

JAVA Program Using Array of Objects
|28
|2144
|15

CS4348 - Operating Systems Concepts
|5
|1324
|177