aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes close() for I/O objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "close() for I/O objects" Watch "close() for I/O objects" New topic
Author

close() for I/O objects

Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
Let's say you've got an exam question on I/O that shows you've got to invoke the close() method and have to choose which reference to invoke it on. Either closing the fileWriter or the bufferedWriter will compile and execute without problems. So which do you choose?



SCJP 1.5
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

You need to add the word boolean before newFile for compilation to succeed. You can close either the fr or the br. It doesnt matter. Not closing them is still legal but inefficient.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Shawn Kuenzler
Ranch Hand

Joined: Apr 16, 2006
Posts: 73
Yeah, I didn't copy in all of the code from the example in the book.

Regardless, there was a drag and drop question on the exam with this issue. So I guess my question is, will the exam accept either fr.close() or br.close() as a correct answer? I'm not sure if the Prometric exam has the logic to allow for multiple correct answers in one item.
Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
I think you should use br.close()
because from java api
I know if you invoke br.close()
fr will close bacause this method is inside br.close()
Herb Tybur
Greenhorn

Joined: May 12, 2006
Posts: 19
Can anybody please give a closure on this? The API for BufferedReader doesn't say anything like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: close() for I/O objects