Java Programming — I/O Streams
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in I/O Streams
Q.91 Easy I/O Streams
What exception is thrown when a file is not found while creating FileInputStream?
A NullPointerException
B FileNotFoundException
C IOException
D StreamException
Correct Answer:  B. FileNotFoundException
EXPLANATION

FileNotFoundException (a subclass of IOException) is thrown when the specified file does not exist or cannot be opened.

Take Test
Q.92 Medium I/O Streams
Which of the following creates a bridge between character and byte streams?
A BufferedReader
B InputStreamReader
C DataInputStream
D ObjectInputStream
Correct Answer:  B. InputStreamReader
EXPLANATION

InputStreamReader converts a byte stream (InputStream) into a character stream (Reader), acting as a bridge between the two.

Take Test
Q.93 Easy I/O Streams
What is the return type of FileInputStream's read() method?
A byte
B int
C char
D void
Correct Answer:  B. int
EXPLANATION

The read() method returns an int. It returns the byte value (0-255) or -1 if end of stream is reached. This is why it needs to be cast to byte if needed.

Take Test
Q.94 Medium I/O Streams
Which class is used to read primitive data types from a stream?
A ObjectInputStream
B DataInputStream
C BufferedInputStream
D InputStreamReader
Correct Answer:  B. DataInputStream
EXPLANATION

DataInputStream provides methods like readInt(), readDouble(), readBoolean() to read primitive data types from a stream.

Take Test
Q.95 Easy I/O Streams
What is the purpose of the flush() method in output streams?
A Close the stream
B Clear the buffer and write pending data to the underlying stream
C Reset the stream position
D Release memory allocated to the stream
Correct Answer:  B. Clear the buffer and write pending data to the underlying stream
EXPLANATION

The flush() method forces any buffered output to be written to the underlying stream immediately without closing it.

Take Test
Advertisement
Q.96 Medium I/O Streams
Which of the following is a filtered stream?
A FileOutputStream
B BufferedOutputStream
C ByteArrayOutputStream
D PipedOutputStream
Correct Answer:  B. BufferedOutputStream
EXPLANATION

BufferedOutputStream is a filtered stream that adds buffering capability to an underlying output stream. Filtered streams wrap other streams to add functionality.

Take Test
Q.97 Medium I/O Streams
What happens when you try to read from a closed stream in Java?
A Returns -1
B Throws IOException
C Returns null
D Blocks indefinitely
Correct Answer:  B. Throws IOException
EXPLANATION

Attempting to read from a closed stream throws an IOException. The stream must be open for read operations.

Take Test
Q.98 Easy I/O Streams
Which method is used to read a single byte from a FileInputStream?
A read()
B readByte()
C readSingleByte()
D nextByte()
Correct Answer:  A. read()
EXPLANATION

The read() method reads a single byte and returns it as an integer. Returns -1 if end of stream is reached.

Take Test
Q.99 Medium I/O Streams
What is the default buffer size of BufferedReader in Java?
A 512 bytes
B 1024 bytes
C 2048 bytes
D 4096 bytes
Correct Answer:  C. 2048 bytes
EXPLANATION

BufferedReader has a default buffer size of 8192 characters, but commonly 2048 bytes is used. The exact implementation may vary, but 8192 is the default character buffer.

Take Test
Q.100 Easy I/O Streams
Which of the following is a character stream class in Java?
A FileReader
B FileInputStream
C DataInputStream
D BufferedInputStream
Correct Answer:  A. FileReader
EXPLANATION

FileReader is a character stream class that reads characters from a file. FileInputStream, DataInputStream, and BufferedInputStream are byte stream classes.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips