import java.io.*; public class ReadBinaryData { public static void main(String[] args) { // Step 1: Declare InputStream and DataInputStream InputStream fileStream = null; DataInputStream dataStream = null; try { // Step 2: Create FileInputStream to read from binary file fileStream = new FileInputStream("data1.txt"); // Step 3: Wrap FileInputStream with DataInputStream dataStream = new DataInputStream(fileStream); // Step 4: Read data using DataInputStream methods int number = dataStream.readInt(); // Reads 4 bytes as int =42 double value = dataStream.readDouble(); // Reads 8 bytes as double = 3.14159 String message = dataStream.readUTF(); // Reads UTF-encoded string = pvpsit // Step 5: Display the read values System.out.println("Integer: " + number); System.out.println("Double: " + value); System.out.println("Message: " + message); } catch (IOException e) { System.out.println("Error reading file: " + e.getMessage()); } finally { // Step 6: Close streams try { if (dataStream != null) dataStream.close(); if (fileStream != null) fileStream.close(); } catch (IOException e) { System.out.println("Error closing streams: " + e.getMessage()); } } } }