← Quiz: File Handling in Java: all 10 questions
Quiz: File Handling in Java · Question 9 of 10
What does this print? (code)
What does this print?
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) {
try {
Files.delete(Path.of("nothing-here.txt"));
System.out.println("deleted");
} catch (NoSuchFileException e) {
System.out.println("no such file");
} catch (IOException e) {
System.out.println("io error");
}
}
}
- A.deleted
- B.io error
- C.Nothing; delete ignores missing files
- D.no such file
Answer & explanation
Correct answer: no such file
Files.delete throws NoSuchFileException for a missing file. Files.deleteIfExists would return false instead.
Can you get the rest right without peeking?
Take the timed Quiz: File Handling in Java quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →