File Handling in Java MCQs Exercise II

Ques 1 File Handling


Which method is used to create a new file in Java?

A createNewFile()
B newFile()
C makeFile()
D createFile()

Ques 2 File Handling


Which class is used to represent a file or directory path in Java?

A Directory
B FilePath
C Path
D File

Ques 3 File Handling


What will be the output of the following Java code snippet?

File file = new File("sample.txt");
System.out.println(file.getName());

A sample.txt
B sample
C Compilation error
D Runtime error

Ques 4 File Handling


What will be the output of the following Java code snippet?

File file = new File("sample.txt");
System.out.println(file.isHidden());

A true
B false
C Compilation error
D Runtime error