A binary File “HOSPITAL.DAT” has structure (Patient_ID, P_Name, Bill_Amount). Write a function that [5]
read the file and tell details of patient whose bill amount is above one Lakh.
Answers
Answer:
A binary File “HOSPITAL.DAT” has structure (Patient_ID, P_Name, Bill_Amount). Write a function that [5]
read the file and tell details of patient whose bill amount is above one Lakh.
Method for Reading the file:
static void readDetails(String fileName) throws IOException {
DataInputStream data = new DataInputStream(new FileInputStream(fileName));
try {
while (true) {
int patientID = data.readInt();
String patientName = data.readUTF();
float billAmount = data.readFloat();
if (billAmount > 1_00_000)
System.out.printf("Patent Name - %s%n" +
"Patient ID - %d%n" +
"Bill Amount - %f", patientName, patientID, billAmount);
}
} catch (EOFException e) {
System.out.println("Finished reading file");
}
data.close( );
}