Govt Exams
The Serializable interface is a marker interface that indicates a class can be serialized. It's found in java.io package and requires no methods to be implemented.
FileReader fr = new FileReader("test.txt");
int data = fr.read();
System.out.println(data);
FileReader.read() returns the ASCII/Unicode value of the character as an integer, not the character itself. It returns -1 when EOF is reached.
DataInputStream is specifically designed to read primitive data types (int, float, double, etc.) from a binary stream using methods like readInt(), readFloat(), etc.
Attempting to read from a closed stream throws an IOException with message 'Stream closed', preventing accidental data processing from invalid sources.
RandomAccessFile allows reading and writing at arbitrary positions using seek() method, useful for direct access to file contents.
FileReader is a character-based stream that reads characters from a file. InputStream and its subclasses are byte-based streams.
The flush() method clears the internal buffer and forces any buffered output to be written to the underlying stream without closing it.
DataInputStream provides methods like readInt(), readDouble(), readBoolean() to read primitive data types from a binary file.
InvalidClassException is thrown when deserialized class's serialVersionUID doesn't match the serialized object.
Mode 'r' allows read-only access. Write operations will throw IOException.