Consider a scenario where you need to write a log file and ensure that each log entry is written to disk immediately for audit compliance. Which classes and/or methods would you use to implement this?
- FileWriter and BufferedWriter classes
- FileOutputStream class and flush() method
- PrintWriter class and sync() method
- RandomAccessFile class and write() method
In this scenario, to ensure that each log entry is written to disk immediately, you can use the PrintWriter class with the sync() method. This combination ensures that data is flushed and written to disk immediately. The other options do not provide the same level of immediate disk writing.
Loading...
Related Quiz
- A ________ block will always execute, whether an exception is thrown or not.
- In a scenario where you are designing a system that will store and manipulate confidential data (like passwords) which will be stored in the form of strings, how would you ensure that this sensitive data is not prone to security issues related to string handling?
- The keyword ________ is used to apply restrictions on class, method, and variable.
- When using a single-thread executor, what happens if a submitted task throws an exception?
- What will be the result of the following Stream operation: Stream.of("a", "b", "c").filter(e -> e.contains("b")).findFirst();?