Entrance Exams
Govt. Exams
Most streams in Java are idempotent regarding close() - calling it multiple times is safe and subsequent calls typically do nothing.
Java NIO (New I/O) uses ByteBuffer and Channels for non-blocking, scalable I/O operations with better performance than traditional streams.
The skip(long n) method skips n bytes in the input stream and returns the number of bytes actually skipped.
BufferedReader's readLine() method is the standard way to read lines. FileInputStream doesn't have readLine(), FileReader doesn't have readLine() either.
The mark() method marks the current position in the stream so it can be returned to later using reset(). Requires markSupported() to return true.
ObjectInputStream and ObjectOutputStream are used for serialization and deserialization of Java objects. Objects must implement Serializable interface.
FileInputStream reads directly from a file byte by byte, while BufferedInputStream wraps another stream and adds buffering to improve performance by reducing I/O operations.
The readLine() method reads a line of text from the BufferedReader, returning a String without the newline character, or null if end of stream is reached.
FileNotFoundException (a subclass of IOException) is thrown when the specified file does not exist or cannot be opened.
InputStreamReader converts a byte stream (InputStream) into a character stream (Reader), acting as a bridge between the two.