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());
}
}
======================================================================