Entrance Exams
Govt. Exams
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.
FileChannel.transferTo() uses OS-level optimizations for file copying, and NIO channels with direct buffers are most efficient for large file transfers.
SequenceInputStream concatenates multiple input streams, reading from them sequentially as if they were a single stream.
GZIPInputStream decompresses GZIP-compressed data, allowing transparent reading of compressed files as normal streams.
The transient keyword marks fields that should not be serialized, useful for excluding sensitive data or non-serializable objects.
BufferedReader combined with custom parsing logic (using split or regex) handles variable-length fields better than fixed-format alternatives.
Maintaining a constant serialVersionUID and implementing version-aware readObject() methods allows deserializing objects from different class versions.
FileChannel supports memory-mapped files and direct buffer manipulation, enabling high-performance I/O operations not possible with traditional streams.
Attempting to read from a closed stream throws an IOException with message 'Stream closed', preventing accidental data processing from invalid sources.