Skip to content
Sharp

I/O · interview question

What does new File("data.txt") do if data.txt doesn't exist?

Multiple choiceMedium
Choose one answer
Answer and explanation

Correct answer

A. It creates a File object representing that path; nothing is created or opened on disk.

Why

File (and Path) are just abstract pathnames. Use exists() / Files.exists(path) to check the disk.

Test yourself on I/O

A free test with instant, explained results. No account needed.

Start free test