Using Text Files - AP Computer Science A
Card 1 of 30
What does the File.length() method return?
What does the File.length() method return?
Tap to reveal answer
Size of the file in bytes. Returns the number of bytes contained in the file.
Size of the file in bytes. Returns the number of bytes contained in the file.
← Didn't Know|Knew It →
What is the method to get the name of a file in Java?
What is the method to get the name of a file in Java?
Tap to reveal answer
getName(). Returns just the filename without the directory path.
getName(). Returns just the filename without the directory path.
← Didn't Know|Knew It →
What exception is commonly thrown when file operations fail?
What exception is commonly thrown when file operations fail?
Tap to reveal answer
IOException. Checked exception thrown when file operations encounter errors.
IOException. Checked exception thrown when file operations encounter errors.
← Didn't Know|Knew It →
Which method is used to flush the output stream in Java?
Which method is used to flush the output stream in Java?
Tap to reveal answer
flush(). Forces any buffered output to be written to the file immediately.
flush(). Forces any buffered output to be written to the file immediately.
← Didn't Know|Knew It →
Identify the method to check end-of-file in BufferedReader.
Identify the method to check end-of-file in BufferedReader.
Tap to reveal answer
read() returns -1. When read() returns -1, it indicates no more data is available.
read() returns -1. When read() returns -1, it indicates no more data is available.
← Didn't Know|Knew It →
Which Java class is used to create a directory?
Which Java class is used to create a directory?
Tap to reveal answer
File. File class provides mkdirs() method to create directory structures.
File. File class provides mkdirs() method to create directory structures.
← Didn't Know|Knew It →
What is the function of the File.exists() method?
What is the function of the File.exists() method?
Tap to reveal answer
Checks if a file exists. Returns true if the file or directory exists on the file system.
Checks if a file exists. Returns true if the file or directory exists on the file system.
← Didn't Know|Knew It →
What method is used to rename a file in Java?
What method is used to rename a file in Java?
Tap to reveal answer
renameTo(). Renames the file to the path specified by the parameter.
renameTo(). Renames the file to the path specified by the parameter.
← Didn't Know|Knew It →
Which method deletes a file in Java?
Which method deletes a file in Java?
Tap to reveal answer
delete(). Removes the file from the file system permanently.
delete(). Removes the file from the file system permanently.
← Didn't Know|Knew It →
Identify the method to list files in a directory.
Identify the method to list files in a directory.
Tap to reveal answer
list() or listFiles(). Returns array of filenames or File objects in the directory.
list() or listFiles(). Returns array of filenames or File objects in the directory.
← Didn't Know|Knew It →
Which Java class provides methods for file manipulation?
Which Java class provides methods for file manipulation?
Tap to reveal answer
File. Provides methods for file system operations like create, delete, rename.
File. Provides methods for file system operations like create, delete, rename.
← Didn't Know|Knew It →
What is the purpose of BufferedWriter in Java?
What is the purpose of BufferedWriter in Java?
Tap to reveal answer
To write text efficiently. Wraps FileWriter to provide buffered writing for better performance.
To write text efficiently. Wraps FileWriter to provide buffered writing for better performance.
← Didn't Know|Knew It →
Which method checks if a File object is a directory?
Which method checks if a File object is a directory?
Tap to reveal answer
isDirectory(). Returns true if the File object represents a directory rather than a file.
isDirectory(). Returns true if the File object represents a directory rather than a file.
← Didn't Know|Knew It →
What is the use of the PrintWriter class in Java?
What is the use of the PrintWriter class in Java?
Tap to reveal answer
To write formatted text. Provides convenient methods like println() for formatted text output.
To write formatted text. Provides convenient methods like println() for formatted text output.
← Didn't Know|Knew It →
Which method retrieves the last modified time of a file?
Which method retrieves the last modified time of a file?
Tap to reveal answer
lastModified(). Returns timestamp of when the file was last modified.
lastModified(). Returns timestamp of when the file was last modified.
← Didn't Know|Knew It →
Which Java package contains classes for file I/O operations?
Which Java package contains classes for file I/O operations?
Tap to reveal answer
java.io. Contains classes like FileReader, FileWriter, BufferedReader for file operations.
java.io. Contains classes like FileReader, FileWriter, BufferedReader for file operations.
← Didn't Know|Knew It →
What does the method File.canRead() check?
What does the method File.canRead() check?
Tap to reveal answer
If file is readable. Returns true if the application can read from the file.
If file is readable. Returns true if the application can read from the file.
← Didn't Know|Knew It →
Which method is used to get the parent directory of a file?
Which method is used to get the parent directory of a file?
Tap to reveal answer
getParent(). Returns the parent directory path as a String.
getParent(). Returns the parent directory path as a String.
← Didn't Know|Knew It →
What does the method File.canWrite() check?
What does the method File.canWrite() check?
Tap to reveal answer
If file is writable. Returns true if the application can write to the file.
If file is writable. Returns true if the application can write to the file.
← Didn't Know|Knew It →
Which method retrieves the absolute path of a file?
Which method retrieves the absolute path of a file?
Tap to reveal answer
getAbsolutePath(). Returns the complete path from the root directory.
getAbsolutePath(). Returns the complete path from the root directory.
← Didn't Know|Knew It →
What is the purpose of BufferedReader in Java?
What is the purpose of BufferedReader in Java?
Tap to reveal answer
To read text efficiently. Wraps FileReader to provide buffered reading for better performance.
To read text efficiently. Wraps FileReader to provide buffered reading for better performance.
← Didn't Know|Knew It →
What does the method ready() in BufferedReader return?
What does the method ready() in BufferedReader return?
Tap to reveal answer
boolean. Returns true if the stream has data available to read without blocking.
boolean. Returns true if the stream has data available to read without blocking.
← Didn't Know|Knew It →
Which class should be used to append text to an existing file?
Which class should be used to append text to an existing file?
Tap to reveal answer
FileWriter with append mode. Constructor parameter true enables appending instead of overwriting.
FileWriter with append mode. Constructor parameter true enables appending instead of overwriting.
← Didn't Know|Knew It →
Which Java class is used to write data to a text file?
Which Java class is used to write data to a text file?
Tap to reveal answer
FileWriter. Standard class for writing character data to files.
FileWriter. Standard class for writing character data to files.
← Didn't Know|Knew It →
What is the method to close a text file in Java?
What is the method to close a text file in Java?
Tap to reveal answer
close(). Essential method to release system resources after file operations.
close(). Essential method to release system resources after file operations.
← Didn't Know|Knew It →
Identify the method to read a line of text from a file in Java.
Identify the method to read a line of text from a file in Java.
Tap to reveal answer
readLine(). BufferedReader method that reads one complete line as a String.
readLine(). BufferedReader method that reads one complete line as a String.
← Didn't Know|Knew It →
Which keyword is used to handle exceptions when reading files?
Which keyword is used to handle exceptions when reading files?
Tap to reveal answer
try-catch. Exception handling structure required for file operations that can throw IOException.
try-catch. Exception handling structure required for file operations that can throw IOException.
← Didn't Know|Knew It →
What is the return type of the readLine() method in Java?
What is the return type of the readLine() method in Java?
Tap to reveal answer
String. Returns a String containing the line content, or null if end of file.
String. Returns a String containing the line content, or null if end of file.
← Didn't Know|Knew It →
Which method is used to write a line of text to a file?
Which method is used to write a line of text to a file?
Tap to reveal answer
write(). FileWriter method to output text data to the file.
write(). FileWriter method to output text data to the file.
← Didn't Know|Knew It →
Which method deletes a file in Java?
Which method deletes a file in Java?
Tap to reveal answer
delete(). Removes the file from the file system permanently.
delete(). Removes the file from the file system permanently.
← Didn't Know|Knew It →