Java File Handling MCQs
This section focuses on the "Java File Handling" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. which class is used to work with files in java?
A. Except class
B. File Class
C. This class
D. io class
View Answer
Ans : B
Explanation: In Java, with the help of File Class, we can work with files.
2. File Class is inside which package?
A. java.util
B. java.awt
C. java.lang
D. java.io
View Answer
Ans : D
Explanation: File Class is inside the java.io package.
3. File handling means _______________ to a file.
A. reading data
B. writing data
C. reading and writing data
D. None of the above
View Answer
Ans : C
Explanation: file handling means reading and writing data to a file.
4. In Java, a sequence of data is known as a stream.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, In Java, a sequence of data is known as a stream.
5. How many types of streams there in java?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B
Explanation: There are two types of streams : Input Stream AND Output Stream
6. Which method is used to reads one byte of data from the input stream?
A. mark()
B. input()
C. read()
D. reset()
View Answer
Ans : C
Explanation: read() : Reads one byte of data from the input stream.
7. Which method is used to forces to write all the data present in an output stream to the destination?
A. close()
B. write()
C. flush()
D. Any of the above
View Answer
Ans : C
Explanation: flush() : Forces to write all the data present in an output stream to the destination.
8. Which method is used to create a new file in Java?
A. file.createNewFile()
B. file.createFile()
C. file.addFile()
D. file.makeFile()
View Answer
Ans : A
Explanation: file.createNewFile()
9. Which method is used to delete a file in Java?
A. file.deleteFile()
B. file.remove()
C. file.erase()
D. file.delete()
View Answer
Ans : D
Explanation: file.delete()
10. The input stream is used to read data from numerous input devices like the keyboard, network, etc.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, The input stream is used to read data from numerous input devices like the keyboard, network, etc.
Discussion