Java MCQ Questions - Java.io
This section focuses on the "Java.io" of 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. Java I/O is used to process the?
A. input
B. output
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: Java I/O (Input and Output) is used to process the input and produce the output.
2. Can we perform file handling in Java by Java I/O API?
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: Java uses the concept of a stream to make I/O operation fast. The java.io package contains all the classes required for input and output operations. We can perform file handling in Java by Java I/O API.
3. In java, how many streams are created for us automatically?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : B
Explanation: In Java, 3 streams are created for us automatically. All these streams are attached with the console.
1. System.out
2. System.in
3. System.err
4. Which method is used to write a byte to the current output stream?
A. public void write(int)throws IOException
B. public void write(byte[])throws IOException
C. public void flush()throws IOException
D. public void close()throws IOException
View Answer
Ans : A
Explanation: public void write(int)throws IOException is used to write a byte to the current output stream.
5. Which method is used to write an array of byte to the current output stream?
A. public void write(int)throws IOException
B. public void write(byte[])throws IOException
C. public void flush()throws IOException
D. public void close()throws IOException
View Answer
Ans : B
Explanation: public void write(byte[])throws IOException is used to write an array of byte to the current output stream.
6. Which of these class is not a member class of java.io package?
A. File
B. StringReader
C. Writer
D. String
View Answer
Ans : D
Explanation: String class is not a member class of java.io package
7. ObjectFilter is a member of java.io package.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : B
Explanation: ObjectFilter is not a member of java.io package.
8. ___________ returns true if called on a file and returns false when called on a directory.
A. IsFile()
B. Isfile()
C. isFile()
D. isfile()
View Answer
Ans : C
Explanation: isFile() returns true if called on a file and returns false when called on a directory.
9. What will be output for the following code?
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File(""/java/system"");
System.out.print(obj.getName());
}
}
A. java
B. system
C. java/system
D. /java/system
View Answer
Ans : B
Explanation: obj.getName() returns the name of the file.
10. What will be output for the following code? Note: file is made in c drive
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File(""/java/system"");
System.out.print(obj.canWrite());
System.out.print("" "" + obj.canRead());
}
}
A. true false
B. false true
C. true true
D. false false
View Answer
Ans : D
Explanation: false false will be output for the following code.
Discussion