Using Text Files - AP Computer Science A

  1. What does the method ready() in BufferedReader return?
    boolean. Returns true if the stream has data available to read without blocking.
  2. 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.
  3. Which Java class is used to write data to a text file?
    FileWriter. Standard class for writing character data to files.
  4. Which method retrieves the last modified time of a file?
    lastModified(). Returns timestamp of when the file was last modified.
  5. What does the File.length() method return?
    Size of the file in bytes. Returns the number of bytes contained in the file.
  6. What is the method to get the name of a file in Java?
    getName(). Returns just the filename without the directory path.
  7. Identify the method to list files in a directory.
    list() or listFiles(). Returns array of filenames or File objects in the directory.
  8. What is the purpose of BufferedWriter in Java?
    To write text efficiently. Wraps FileWriter to provide buffered writing for better performance.
  9. Which method checks if a File object is a directory?
    isDirectory(). Returns true if the File object represents a directory rather than a file.
  10. What is the use of the PrintWriter class in Java?
    To write formatted text. Provides convenient methods like println() for formatted text output.
  11. Which keyword is used to handle exceptions when reading files?
    try-catch. Exception handling structure required for file operations that can throw IOException.
  12. What does the method File.canWrite() check?
    If file is writable. Returns true if the application can write to the file.
  13. How to create a new file in Java?
    createNewFile(). Creates a new empty file if it doesn't already exist.
  14. 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.
  15. Which class should be used to append text to an existing file?
    FileWriter with append mode. Constructor parameter true enables appending instead of overwriting.
  16. What is the method to close a text file in Java?
    close(). Essential method to release system resources after file operations.
  17. What exception is commonly thrown when file operations fail?
    IOException. Checked exception thrown when file operations encounter errors.
  18. What method is used to rename a file in Java?
    renameTo(). Renames the file to the path specified by the parameter.
  19. What is the purpose of BufferedReader in Java?
    To read text efficiently. Wraps FileReader to provide buffered reading for better performance.
  20. Which method is used to get the parent directory of a file?
    getParent(). Returns the parent directory path as a String.
  21. 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.
  22. Which method is used to flush the output stream in Java?
    flush(). Forces any buffered output to be written to the file immediately.
  23. Which method retrieves the absolute path of a file?
    getAbsolutePath(). Returns the complete path from the root directory.
  24. What does the method File.canRead() check?
    If file is readable. Returns true if the application can read from the file.
  25. Which Java package contains classes for file I/O operations?
    java.io. Contains classes like FileReader, FileWriter, BufferedReader for file operations.
  26. Which Java class is used to create a directory?
    File. File class provides mkdirs() method to create directory structures.
  27. Identify the method to check end-of-file in BufferedReader.
    read() returns -1. When read() returns -1, it indicates no more data is available.
  28. Which method deletes a file in Java?
    delete(). Removes the file from the file system permanently.
  29. Which method is used to write a line of text to a file?
    write(). FileWriter method to output text data to the file.
  30. Which Java class provides methods for file manipulation?
    File. Provides methods for file system operations like create, delete, rename.

Study these flashcards