-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.0
-
sparc
-
solaris_2.5.1
Name: akC57697 Date: 07/14/98
The java.io.RandomAccessFile.readInt() does not throw EOFException and hangs
if this file reaches the end before reading four bytes.
The documentation says:
"
public final native int readInt() throws IOException
Reads a signed 32-bit integer from this file. This method reads 4
bytes from the file, starting at the current file pointer.
....
This method blocks until the four bytes are read, the end of the
stream is detected, or an exception is thrown.
@return the next four bytes of this file, interpreted as an
int.
@exception EOFException if this file reaches the end before reading
^^^^^^^^^^^^^^^^^^^
four bytes.
@exception IOException if an I/O error occurs.
"
The example:
------------------------------8-<--------------------------------------------
import java.io.*;
class Test {
public static void main(String[] argv) {
try {
FileOutputStream fos = new FileOutputStream("File.dat");
fos.write(1);
fos.close();
RandomAccessFile raf = new RandomAccessFile("File.dat","rw");
try {
System.out.println("Read int ...");
int i=raf.readInt();
System.out.println("No EOFException");
System.exit(1);
} catch (IOException ex) {
System.out.println("OKAY");
System.exit(0);
}
} catch (Exception e) {
System.out.println("Unexpected:"+e);
System.exit(0);
}
}
}
---------------------------->-8----------------------------------------------
Output:
Read int ...
^C
java full version "JDK-1.2fcs-B"
======================================================================
- duplicates
-
JDK-4137835 java.io.RandomAccessFile.writeInt(),readInt() methods results in four kernel cal
- Closed