Govt Exams
The default buffer size for BufferedInputStream is 8192 bytes (8 KB). This can be overridden by using the constructor BufferedInputStream(InputStream, int size).
FileOutputStream(String filename) by default overwrites existing file. Use FileOutputStream(File, boolean append) with true to append.
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.
Processing large files in chunks using BufferedInputStream with an appropriate buffer size (like 8KB-64KB) balances memory usage and I/O efficiency.
InputStreamReader is a bridge from byte streams to character streams and accepts any InputStream with optional charset. FileReader is specifically for file input with default charset.
Streams are not thread-safe. Concurrent access by multiple threads can lead to data corruption. Synchronization or separate streams per thread are needed.
InvalidClassException is thrown when serialVersionUID doesn't match during deserialization, indicating class incompatibility.
BufferedReader.readLine() is the most efficient way to read complete lines as it buffers input and provides a dedicated method for line reading.