File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

close() for I/O objects

 
Shawn Kuenzler
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shawn Kuenzler
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic