import java.io.*; public class ReadFileExample { public static void main(String[] args) { // Step 1: Declare InputStream variables InputStream inputStream = null; //FileInputStream fileStream = null; BufferedInputStream bufferedInput = null; try { // Step 2: Create FileInputStream to read from file inputStream = new FileInputStream("data.txt"); //fileStream = new FileInputStream("data.txt"); // Step 3: Wrap FileInputStream with BufferedInputStream bufferedInput = new BufferedInputStream(inputStream); // Step 4: Read data byte by byte int byteData; while ((byteData = bufferedInput.read()) != -1) { // Convert byte to character and print System.out.print((char) byteData); } } catch (IOException e) { System.out.println("Error reading file: " + e.getMessage()); } finally { // Step 5: Close streams in reverse order of opening try { if (bufferedInput != null) bufferedInput.close(); if (inputStream != null) inputStream.close(); } catch (IOException e) { System.out.println("Error closing streams: " + e.getMessage()); } } } }