Solved

Consider the Following Code Snippet: PrintWriter OutputFile = New PrintWriter(filename);

Question 88

Multiple Choice

Consider the following code snippet: PrintWriter outputFile = new PrintWriter(filename) ;
WriteData(outputFile) ;
OutputFile.close() ;
How can the program ensure that the file will be closed if an exception occurs on the writeData call?


A) The program does not need to take any action, because the output file will be automatically closed when the exception occurs.
B) The program should place the outputFile.close() statement within a try block to ensure that the file will be closed.
C) It is not possible to ensure that the file will be closed when the exception occurs.
D) The program should place the outputFile.close() statement within a finally clause of a try block to ensure that the file is closed.

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents