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