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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *