Java Intermediate

0% completed

Previous
Next
Quiz
Question 1
Which package contains the File class used for file handling?
A
java.lang
B
java.io
C
java.util
D
java.nio
Question 2
Examine the following code snippet:
import java.io.File;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        try {
            File file = new File("data.txt");
            if (file.createNewFile()) {
                System.out.println("File created successfully.");
            } else {
                System.out.println("File already exists.");
            }
        } catch (IOException e) {
            System.out.println("Error occurred while creating the file.");
        }
    }
}
What does this code do?
A
It reads the contents of "data.txt".
B
It deletes the file "data.txt".
C
It writes "data.txt" to the console.
D
It creates a new file named "data.txt" if it does not exist.
Question 3
Which method is used to delete a file in Java?
A
deleteFile()
B
remove()
C
delete()
D
clear()

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next