Page 1 of 1

About Question enthuware.ocpjp.v8.2.1552 :

Posted: Mon Dec 14, 2015 10:51 am
by mrmuiz
I'm working on Java 1.8.0_45.

Code: Select all

Files.newInputStream(Path path, OpenOption... options)
invokes

Code: Select all

FileSystemProvider.newInputStream(Path path, OpenOption... options)
where you can find

Code: Select all

            for (OpenOption opt: options) {
                // All OpenOption values except for APPEND and WRITE are allowed
                if (opt == StandardOpenOption.APPEND ||
                    opt == StandardOpenOption.WRITE)
                    throw new UnsupportedOperationException("'" + opt + "' not allowed");
            }
In fact, all the five options compile in my jre/os. Anyway, being there hardcoded in the class, I think it can be considered a general rule in case of reading.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Wed Mar 09, 2016 5:45 pm
by javalass
Regarding option 4, I get

Code: Select all

UnsupportedOperationException: 'APPEND' not allowed
whether the file already exists or not.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Wed Mar 09, 2016 5:54 pm
by javalass
And option 5 executes fine if the file exists. I'm on Windows.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Wed Mar 09, 2016 11:21 pm
by admin
Fixed.
thank you for your feedback!
Paul.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Thu Mar 10, 2016 4:36 am
by Russtam
We have correct answer
new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.DELETE_ON_CLOSE}
and that explanation:
Thus, READ and TRUNCATE_EXISTING (or WRITE, APPEND, or DELETE_ON_CLOSE) cannot go together.
one excludes other

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Thu Mar 10, 2016 9:37 am
by admin
Unfortunately, it works on Java 8 but does not work on Java 7. So the option is marked as correct for Java 8 version and wrong for Java 7.
The explanation has now been updated accordingly.

thank you!
Paul.

Re: About Question enthuware.ocpjp.v8.2.1552 :

Posted: Thu Mar 10, 2016 10:08 am
by javalass
That explains! Thanks for checking.