/*
  Suppose a binary data file named E17_03.dat has been created and its data
  are created using writeInt(int) in DataOutputStream. The file contains an
  unspecified number of integers. Write a program to find the sum of the
  integers.
*/

import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.File;

public class E17_03 {
  public static void main(String[] args) throws IOException {
    // Create E17_03.dat if it doesn't already exist
    File file = new File("E17_03.dat");

    if (!file.exists()) {
      try (
        DataOutputStream output =
          new DataOutputStream(
            new BufferedOutputStream(new FileOutputStream(file)));
      ) {
        int ran = (int)(Math.random() * 100) + 10;
        for (int i = 0; i < ran; i++) {
          ran = (int)(Math.random() * 100);
          output.writeInt(ran);
        }
      }
    }

    // Sum the contents of E17_03.dat
    try (
      DataInputStream input =
        new DataInputStream(
          new BufferedInputStream(new FileInputStream(file)));
    ) {
      int sum = 0;
      while (input.available() > 0) {
        sum += input.readInt();
      }

      System.out.println("The sum is " + sum);
    }
  }
}

@@ -468,16 +468,45 @@
 eption;%0A
+import java.io.EOFException;%0A
 import j
@@ -1108,16 +1108,33 @@
 _03.dat%0A
+    int sum = 0;%0A
     try 
@@ -1271,31 +1271,25 @@
 %7B%0A      int 
-sum = 0
+r
 ;%0A      whil
@@ -1295,29 +1295,35 @@
 le (
+(r = 
 input.
-available() %3E 0
+readInt()) != -1
 ) %7B%0A
@@ -1341,33 +1341,70 @@
  += 
-input.readInt();%0A      %7D%0A
+r;%0A      %7D%0A    %7D catch (EOFException ex) %7B%0A      // do nothing
 %0A   

Change loop condition in input code