File I/O — Concept Check
Questions on File I/O. Java provides multiple APIs for reading and writing files — from classic streams to the modern java.nio.file.Files utility class.
Questions in this quiz
8 questions on File I/O — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You are using Files.writeString to append data to a file. What must you ensure?
- AUse StandardCharsets.ISO_8859_1
- BUse StandardOpenOption.APPEND
- CCall stream.close()
- DUse Files.newBufferedWriter
2.A developer uses Files.lines(path) for a large file but forgets to close the stream. What happens?
- AThe file is automatically closed
- BThe file becomes corrupted
- CThe file handle remains open
- DThe file content is lost
3.What is the purpose of using try-with-resources in file I/O operations?
- AConverts file to UTF-8
- BImproves file read speed
- CEncrypts file data
- DAutomatically closes resources
4.When reading a file line-by-line with BufferedReader, what must you specify?
- ABuffer size
- BFile permissions
- CFile size
- DCharset explicitly
5.A file operation using Files.move() fails. What could be a reason?
- ASource and destination are the same
- BATOMIC_MOVE not supported
- CFile is too large
- DFile is read-only
6.What happens if you try to delete a non-existent file using Files.delete()?
- ASilently succeeds
- BThrows an exception
- CCreates the file
- DLogs a warning
7.You need to read a file's content as a single string. Which method is ideal?
- ABufferedReader.readLine
- BFiles.lines
- CFiles.readString
- DFiles.newBufferedReader
8.In Java, what is a key benefit of using Files.walk()?
- ACompresses file content
- BReads large files quickly
- CEnumerates directory trees
- DEnsures thread safety