This section of our 1000+ Java MCQs focuses on java.io library of Java Programming Language.
1. Which of these packages contain classes and interfaces used for input & output operations of a program?
a) java.util
b) java.lang
c) java.io
d) all of the mentioned
View Answer
Explanation: java.io provides support for input and output operations.
2. Which of these class is not a member class of java.io package?
a) String
b) StringReader
c) Writer
d) File
View Answer
Explanation: None.
3. Which of these interface is not a member of java.io package?
a) DataInput
b) ObjectInput
c) ObjectFilter
d) FileFilter
View Answer
Explanation: None.
4. Which of these class is not related to input and output stream in terms of functioning?
a) File
b) Writer
c) InputStream
d) Reader
View Answer
Explanation: A File describes properties of a file, a File object is used to obtain or manipulate the information associated with a disk file, such as the permissions, time date, and directories path, and to navigate subdirectories.
5. Which of these is specified by a File object?
a) a file in disk
b) directory path
c) directory in disk
d) none of the mentioned
View Answer
Explanation: None.
6. Which of these is method for testing whether the specified element is a file or a directory?
a) IsFile()
b) isFile()
c) Isfile()
d) isfile()
View Answer
Explanation: isFile() returns true if called on a file and returns false when called on a directory.
7. What will be the output of the following Java 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
Explanation: obj.getName() returns the name of the file.
Output:
$ javac files.java
$ java files
system
8. What will be the output of the following Java program? (Note: file is made in c drive.)
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("c:/java/system");
System.out.print(obj.getAbsolutePath());
}
}
a) java
b) system
c) c:/java/system
d) c:\java\system
View Answer
Explanation: None.
Output:
$ javac files.java $ java files c:\java\system
9. What will be the output of the following Java program considering that the filename sanfoundry.java exists and is readable but not writable?
import java.io.*;
class files
{
public static void main(String args[])
{
File obj = new File("sanfoundry.java");
System.out.print(obj.canWrite());
System.out.print(" " + obj.canRead());
}
}
a) true false
b) false true
c) true true
d) false false
View Answer
Explanation: None.
Output:
$ javac files.java $ java files false true
10. What will be the output of the following Java program? (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.getParent());
System.out.print(" " + obj.isFile());
}
}
a) java true
b) java false
c) \java false
d) \java true
View Answer
Explanation: getparent() giver the parent directory of the file and isfile() checks weather the present file is a directory or a file in the disk.
Output:
$ javac files.java $ java files \java false
Sanfoundry Global Education & Learning Series – Java Programming Language.
- Check Java Books
- Practice Programming MCQs
- Check Programming Books
- Practice BCA MCQs
- Apply for Computer Science Internship