import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class BinaryFileExample { public static void main(String[] args) { try (FileInputStream inputStream = new FileInputStream("input.dat"); FileOutputStream outputStream = new FileOutputStream("output.dat")) { int data; while ((data = inputStream.read()) != -1) { outputStream.write(data); } System.out.println("File copied successfully."); } catch (IOException e) { System.out.println("An error occurred: " + e.getMessage()); } } }