Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4081705

java.io.DataInputStream: Cannot read last double from file, get EOFException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • None
    • x86
    • windows_95



      Name: sg39081 Date: 09/25/97


      The following example receives java.io.EOFException when I try
      to read the last double in the file. I receive the same exception
      in 1.1, but it works fine in 1.0

      The following is the output:
      3.14159
      That was the value of pi
      This is the value of pi/2:
      java.io.EOFException
              at java.io.DataInputStream.readInt(DataInputStream.java:371)
              at java.io.DataInputStream.readLong(DataInputStream.java:405)
              at java.io.DataInputStream.readDouble(DataInputStream.java:448)
              at IOBug.main(IOBug.java:25)

      // Java 1.1 & 1.2 IO Bug
      import java.io.*;

      public class IOBug {
        public static void main(String args[]) throws Exception {
          DataOutputStream out =
            new DataOutputStream(
              new BufferedOutputStream(
                new FileOutputStream("Data.txt")));
          out.writeDouble(3.14159);
          out.writeBytes("That was the value of pi\n");
          out.writeBytes("This is the value of pi/2:\n");
          out.writeDouble(3.14159/2);
          out.close();

          DataInputStream in =
            new DataInputStream(
              new BufferedInputStream(
                new FileInputStream("Data.txt")));
          BufferedReader inbr =
            new BufferedReader(
              new InputStreamReader(in));
          // The doubles written BEFORE the line of text
          // read back correctly:
          System.out.println(in.readDouble());
          // Read the lines of text:
          System.out.println(inbr.readLine());
          System.out.println(inbr.readLine());
          // Trying to read the doubles after the line
          // produces an end-of-file exception:
          System.out.println(in.readDouble());
        }
      }
      ======================================================================

            dviswanasunw Deepa Viswanathan (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: