Entrance Exams
Govt. Exams
The Serializable interface must be implemented to serialize objects. It is a marker interface with no methods. Classes implementing it can be serialized using ObjectOutputStream.
The default buffer size for BufferedInputStream is 8192 bytes (8 KB). This can be overridden by using the constructor BufferedInputStream(InputStream, int size).
FileInputStream is a byte stream class, not a character stream. FileReader, BufferedWriter, and PrintWriter are all character stream classes.
RandomAccessFile supports seek() operation to jump to specific file positions, useful for reading log tail or accessing specific records directly.
ObjectInputStream/ObjectOutputStream with serialVersionUID ensures compatibility, versioning, and is the standard approach for object persistence in Java.
FileOutputStream(String filename) by default overwrites existing file. Use FileOutputStream(File, boolean append) with true to append.
PrintWriter uses buffering by default. If flush() or close() is not called, buffered data may not be written to disk.
Try-with-resources (try-with-resources statement) automatically closes AutoCloseable resources, ensuring proper cleanup even if exceptions occur.
FileChannel provides non-blocking and efficient I/O operations, memory-mapped file access, and file locking capabilities compared to traditional streams.
available() returns an estimate of bytes that can be read without blocking. It doesn't return total file size.