I/O interview questions
Streams vs readers, buffering, NIO.2, serialization.
4 questions with answers and explanations · 2 flashcards
Key ideas
- Byte streams (
InputStream/OutputStream) vs character streams (Reader/Writer, which handle charsets). - Wrap with
BufferedReader/BufferedWriterto avoid one system call per character. - NIO.2:
PathandFiles(Files.readAllLines,Files.lines,Files.writeString). - Serialization needs
Serializable;transientandstaticfields aren't serialized. Never deserialize untrusted data.
Questions
- Which class should you wrap around a FileReader to read text efficiently line by line?Multiple choiceEasy
- Which java.nio.file.Files method reads all lines of a small text file into a List<String>? (method name)Fill in the blankMedium
- Which statements about Java serialization are true? Select all that apply.Select all that applyMedium
- What does new File("data.txt") do if data.txt doesn't exist?Multiple choiceMedium