Question: Which one is correct? Why? Incorrect Question 9 0/1 pts Consider the following code snippet: PrintWriter outputFile - new PrintWriter(filename); writeDataCoutputFile); outputFile.close How can the

Which one is correct? Why?
Incorrect Question 9 0/1 pts Consider the following code snippet: PrintWriter outputFile - new PrintWriter(filename); writeDataCoutputFile); outputFile.close How can the program ensure that the file will be closed if an exception occurs on the writeData call? It is not possible to ensure that the file will be closed when the exception occurs The program does not need to take any action, because the output file will be automatically closed when the exception occurs The program should place the outputFile.closeO a try block to ensure that the file will be closed. statement within The program should declare the PrintWriter variable in a try-with- esources statement to ensure that the file is closed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
