About Question enthuware.ocpjp.v8.2.1811 :
Moderator: admin
-
- Posts: 49
- Joined: Mon Jul 27, 2015 4:34 am
- Contact:
About Question enthuware.ocpjp.v8.2.1811 :
Option 2 and 4 are both correct answers. Question is "which instruction will cause file to be written", and both of them will do the job (even though "bfw.close();" is a cleaner solution)
-
- Site Admin
- Posts: 9804
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
Actually, the question is, "Which of the following lines is required to be inserted...." A call to close() is required but a call to flush() is not.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 49
- Joined: Mon Jul 27, 2015 4:34 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
Uhm, I don't agree 100%, sentence is "Which of the following lines is required to be inserted[...]so that content in b.java will be overwritten...".
It's like asking which method will cause a transaction to be committed: "commit" is righter than "setAutocommit(true)", but both do what's asked.
But I have to admit that I've experienced borderline questions like these in the exam
It's like asking which method will cause a transaction to be committed: "commit" is righter than "setAutocommit(true)", but both do what's asked.
But I have to admit that I've experienced borderline questions like these in the exam
-
- Posts: 8
- Joined: Tue Jan 11, 2022 4:41 am
Re: About Question enthuware.ocpjp.v8.2.1811 :
I guess the content will not be overwritten with contents in a.java. Technically because it will not add the new line characters.Of course that does not change the answer.
-
- Posts: 2
- Joined: Tue Aug 10, 2021 8:37 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
Hi,
Are we certain close() calls flush() behind the scene in every situation? I seem to find contradictory information while searching on this topic.
Thank you!
Are we certain close() calls flush() behind the scene in every situation? I seem to find contradictory information while searching on this topic.
Thank you!
-
- Site Admin
- Posts: 9804
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
Well, the JavaDoc description of BufferedWriter clearly says that close flushes the stream. Where did you find contradictory information?
If you like our products and services, please help us by posting your review here.
-
- Posts: 13
- Joined: Wed Sep 28, 2022 9:41 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
Why BufferedReader was not closed, as well? if it has the method .close()"Closes the stream and releases any system resources associated with it."
See that: https://docs.oracle.com/javase/8/docs/a ... ml#close--
See that: https://docs.oracle.com/javase/8/docs/a ... ml#close--
-
- Site Admin
- Posts: 9804
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1811 :
While it is a good idea to close the BufferedReader object as well, it is has no impact on the writing part, which is done using BufferedWriter. In other words, it is irrelevant for the situation given in the problem statement.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 1 guest