Files and Exception Handling - streams and files, multi-file programs, exception and event handling - Question Bank
1. Which C++ stream manipulator is used to move the file's write/read position to a specific location?
2. What does the 'x' mode signify when opening a file in Python?
3. In the context of multi-file programs, what is a common way to link or compile different source files together?
4. Which Java exception is a general superclass for all errors and exceptions that are not runtime exceptions?
5. What is the main purpose of the `raise` statement in Python?
6. In C++, what does the `seekg()` function typically do?
7. Which Java class is used for reading primitive data types and strings from binary files?
8. What is the difference between `os.path.exists()` and `os.path.isfile()` in Python?
9. In Java, what is the purpose of the `Serializable` interface?
10. What is the role of the `catch` block in Java?
11. Which Python exception is raised when you try to write to a file that has been opened in read-only mode?
12. What is the standard way to handle potential errors when performing file operations in C++?
13. Which Java exception is a superclass for most other I/O related exceptions?
14. In Python, what does the 'rb' mode signify when opening a file?
15. What is the purpose of the `try-with-resources` statement in Java (introduced in Java 7)?
16. Which of the following is a common scenario where multi-file programming is essential?
17. What is the primary advantage of using `BufferedReader` over `FileReader` for reading large text files in Java?
18. Which Python function is used to check if a file exists?
19. In C++, what is the purpose of the `flush()` method on a file stream?
20. What is a 'daemon thread' in Java?
21. Which Java class is used for writing character data to files, often with buffering for efficiency?
22. What is the primary role of the `finally` clause in Python's `try...except...finally` structure?
23. In C++, what happens if you try to open a file that does not exist using `ofstream` in its default mode?
24. What does the `EOFException` in Java typically indicate?
25. Which of the following is NOT a common mode for opening files in Python?
26. What is the standard extension for Java archive files, often used to package multiple class files and resources for distribution?
27. What is the difference between a checked and an unchecked exception in Java?
28. In Python, what is the purpose of the `seek()` method when working with files?
29. Which C++ stream object is used for both reading from and writing to files?
30. What does the `throws` keyword in a Java method signature indicate?
31. In Java, which method is typically used to read a line of text from a `BufferedReader`?
32. What is the primary function of an 'event handler'?
33. Which Python exception is raised when a file or directory is requested but does not exist?
34. What is a 'stream' in the context of file handling?
35. In C++, what is the role of the `std::ios::binary` flag when opening a file?
36. Which exception class in Java represents an error related to file operations, such as a file not being found?
37. What is the primary benefit of using multi-file programs?
38. In Python, using the `with open(...) as f:` construct, when is the file automatically closed?
39. Which Java class is fundamental for handling file input and output operations?
40. What is an 'event' in the context of programming?
41. What does the 'a' mode signify when opening a file in Python?
42. Which of the following C++ stream objects is used for reading from files?
43. What is the purpose of the `finally` block in Java's exception handling?
44. In C++, what is the standard library that provides file stream classes like `ifstream` and `ofstream`?
45. Which keyword is used to explicitly throw an exception in Java?
46. What is the purpose of a `try-catch` block in exception handling?
47. What does the 'w' mode signify when opening a file in Python?
48. In Python, what is the primary function used to open a file?
49. Which of the following is a common stream type used for reading data from a file in Java?