PrepGo

AP Computer Science A Flashcards: Using Text Files

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What is a file in the context of programming?
A file is storage for data that persists when the program is not running. The data in a file can be retrieved during program execution.
Card 1 of 10

All Flashcards (10)

What is a file in the context of programming?
A file is storage for data that persists when the program is not running. The data in a file can be retrieved during program execution.
What is `IOException`?
`IOException` is an exception that signals that an I/O (Input/Output) error of some sort has occurred, such as a file not being found.
Why is it required to handle potential errors when attempting to open a file?
It is required to handle errors because the file with the provided name may not be found or cannot be opened, which would cause the program to fail.
Which two `Scanner` methods would you use to read a floating-point number and a single word, respectively?
You would use the `nextDouble()` method to read a floating-point number and the `next()` method to read a single word or token.
How can a method indicate that it might fail to open a file?
A method can indicate this by adding `throws IOException` to its header, which signals that an input/output error might occur.
What is the purpose of the `close()` method for a `Scanner` reading a file?
The `close()` method is called to release the system resources associated with the file being read by the `Scanner`.
Which `Scanner` method reads an entire line of text from a file?
The `nextLine()` method is used to read all characters from the scanner's current position up to the next line separator.
How would you read an integer value from a text file using a `Scanner`?
You would call the `nextInt()` method on the `Scanner` object to scan the next token of input as an integer.
What is the purpose of the `Scanner(File f)` constructor?
This constructor creates a new `Scanner` object that is configured to read data directly from the specified file `f`.
Which `Scanner` method is used to check if there is more data to read from a file?
The `hasNext()` method is used to determine if the scanner has more data to read, returning true if it does and false otherwise.