• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

close() for I/O objects

 
Ranch Hand
Posts: 73
  • 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?

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • 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
  • 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.
 
Ranch Hand
Posts: 83
  • 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()
 
Greenhorn
Posts: 19
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic