AP Computer Science a Flashcards: Using Text Files

Study Using Text Files in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Using Text Files

0 mastered0 still learning

0% Complete

QUESTION
1/ 60

What is the method to close a text file in Java?

Tap card or press Space to flip

ANSWER

close(). Essential method to release system resources after file operations.

How well did you know it?

Card 1 / 60

What this deck covers

This deck focuses on Using Text Files, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: What is the method to close a text file in Java?

Answer: close(). Essential method to release system resources after file operations.

Flashcard 2: What does the method ready() in BufferedReader return?

Answer: boolean. Returns true if the stream has data available to read without blocking.

Flashcard 3: What is the function of the File.exists() method?

Answer: Checks if a file exists. Returns true if the file or directory exists on the file system.

Flashcard 4: Which Java class is used to write data to a text file?

Answer: FileWriter. Standard class for writing character data to files.

Flashcard 5: Identify the method to read a line of text from a file in Java.

Answer: readLine(). BufferedReader method that reads one complete line as a String.

Flashcard 6: Which method retrieves the last modified time of a file?

Answer: lastModified(). Returns timestamp of when the file was last modified.

Flashcard 7: What does the File.length() method return?

Answer: Size of the file in bytes. Returns the number of bytes contained in the file.

Flashcard 8: What is the method to get the name of a file in Java?

Answer: getName(). Returns just the filename without the directory path.

Flashcard 9: Identify the method to list files in a directory.

Answer: list() or listFiles(). Returns array of filenames or File objects in the directory.

Flashcard 10: What is the purpose of BufferedWriter in Java?

Answer: To write text efficiently. Wraps FileWriter to provide buffered writing for better performance.

Flashcard 11: Which method checks if a File object is a directory?

Answer: isDirectory(). Returns true if the File object represents a directory rather than a file.

Flashcard 12: What is the use of the PrintWriter class in Java?

Answer: To write formatted text. Provides convenient methods like println() for formatted text output.

Flashcard 13: What is the use of the PrintWriter class in Java?

Answer: To write formatted text. Provides convenient methods like println() for formatted text output.

Flashcard 14: Which keyword is used to handle exceptions when reading files?

Answer: try-catch. Exception handling structure required for file operations that can throw IOException.

Flashcard 15: What does the method File.canWrite() check?

Answer: If file is writable. Returns true if the application can write to the file.

Flashcard 16: What is the return type of the readLine() method in Java?

Answer: String. Returns a String containing the line content, or null if end of file.

Flashcard 17: How to create a new file in Java?

Answer: createNewFile(). Creates a new empty file if it doesn't already exist.

Flashcard 18: Which Java class provides methods for file manipulation?

Answer: File. Provides methods for file system operations like create, delete, rename.

Flashcard 19: What is the purpose of BufferedWriter in Java?

Answer: To write text efficiently. Wraps FileWriter to provide buffered writing for better performance.

Flashcard 20: How to create a new file in Java?

Answer: createNewFile(). Creates a new empty file if it doesn't already exist.

Flashcard 21: What is the return type of the readLine() method in Java?

Answer: String. Returns a String containing the line content, or null if end of file.

Flashcard 22: Which class should be used to append text to an existing file?

Answer: FileWriter with append mode. Constructor parameter true enables appending instead of overwriting.

Flashcard 23: Which method retrieves the last modified time of a file?

Answer: lastModified(). Returns timestamp of when the file was last modified.

Flashcard 24: What is the method to close a text file in Java?

Answer: close(). Essential method to release system resources after file operations.

Flashcard 25: Which Java class is used to write data to a text file?

Answer: FileWriter. Standard class for writing character data to files.

Flashcard 26: What exception is commonly thrown when file operations fail?

Answer: IOException. Checked exception thrown when file operations encounter errors.

Flashcard 27: What does the method File.canWrite() check?

Answer: If file is writable. Returns true if the application can write to the file.

Flashcard 28: What exception is commonly thrown when file operations fail?

Answer: IOException. Checked exception thrown when file operations encounter errors.

Flashcard 29: Which method is used to get the parent directory of a file?

Answer: getParent(). Returns the parent directory path as a String.

Flashcard 30: What method is used to rename a file in Java?

Answer: renameTo(). Renames the file to the path specified by the parameter.

Flashcard 31: What is the purpose of BufferedReader in Java?

Answer: To read text efficiently. Wraps FileReader to provide buffered reading for better performance.

Flashcard 32: Which Java class is used to create a directory?

Answer: File. File class provides mkdirs() method to create directory structures.

Flashcard 33: What does the method ready() in BufferedReader return?

Answer: boolean. Returns true if the stream has data available to read without blocking.

Flashcard 34: What is the function of the File.exists() method?

Answer: Checks if a file exists. Returns true if the file or directory exists on the file system.

Flashcard 35: Which method is used to write a line of text to a file?

Answer: write(). FileWriter method to output text data to the file.

Flashcard 36: Which method is used to get the parent directory of a file?

Answer: getParent(). Returns the parent directory path as a String.

Flashcard 37: Identify the method to read a line of text from a file in Java.

Answer: readLine(). BufferedReader method that reads one complete line as a String.

Flashcard 38: Which method retrieves the absolute path of a file?

Answer: getAbsolutePath(). Returns the complete path from the root directory.

Flashcard 39: Which method is used to flush the output stream in Java?

Answer: flush(). Forces any buffered output to be written to the file immediately.

Flashcard 40: Which class should be used to append text to an existing file?

Answer: FileWriter with append mode. Constructor parameter true enables appending instead of overwriting.

Flashcard 41: What method is used to rename a file in Java?

Answer: renameTo(). Renames the file to the path specified by the parameter.

Flashcard 42: Identify the method to list files in a directory.

Answer: list() or listFiles(). Returns array of filenames or File objects in the directory.

Flashcard 43: Which method retrieves the absolute path of a file?

Answer: getAbsolutePath(). Returns the complete path from the root directory.

Flashcard 44: Which Java package contains classes for file I/O operations?

Answer: java.io. Contains classes like FileReader, FileWriter, BufferedReader for file operations.

Flashcard 45: What does the method File.canRead() check?

Answer: If file is readable. Returns true if the application can read from the file.

Flashcard 46: What does the method File.canRead() check?

Answer: If file is readable. Returns true if the application can read from the file.

Flashcard 47: What is the method to get the name of a file in Java?

Answer: getName(). Returns just the filename without the directory path.

Flashcard 48: Which method checks if a File object is a directory?

Answer: isDirectory(). Returns true if the File object represents a directory rather than a file.

Flashcard 49: Which method deletes a file in Java?

Answer: delete(). Removes the file from the file system permanently.

Flashcard 50: Which Java package contains classes for file I/O operations?

Answer: java.io. Contains classes like FileReader, FileWriter, BufferedReader for file operations.

Flashcard 51: Which keyword is used to handle exceptions when reading files?

Answer: try-catch. Exception handling structure required for file operations that can throw IOException.

Flashcard 52: Which Java class is used to create a directory?

Answer: File. File class provides mkdirs() method to create directory structures.

Flashcard 53: Identify the method to check end-of-file in BufferedReader.

Answer: read() returns -1. When read() returns -1, it indicates no more data is available.

Flashcard 54: Which method deletes a file in Java?

Answer: delete(). Removes the file from the file system permanently.

Flashcard 55: What does the File.length() method return?

Answer: Size of the file in bytes. Returns the number of bytes contained in the file.

Flashcard 56: Which method is used to write a line of text to a file?

Answer: write(). FileWriter method to output text data to the file.

Flashcard 57: Identify the method to check end-of-file in BufferedReader.

Answer: read() returns -1. When read() returns -1, it indicates no more data is available.

Flashcard 58: Which method is used to flush the output stream in Java?

Answer: flush(). Forces any buffered output to be written to the file immediately.

Flashcard 59: Which Java class provides methods for file manipulation?

Answer: File. Provides methods for file system operations like create, delete, rename.

Flashcard 60: What is the purpose of BufferedReader in Java?

Answer: To read text efficiently. Wraps FileReader to provide buffered reading for better performance.