About Question enthuware.ocpjp.v7.2.1538 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Student
Posts: 53
Joined: Fri Sep 20, 2013 7:20 am
Contact:

About Question enthuware.ocpjp.v7.2.1538 :

Post by Student »

"Observe that some combinations such as StandardOpenOption.CREATE, StandardOpenOption.READ do not make sense if put together and therefore an IllegalArgumentException will be thrown in such cases."

I think it might be that you can't specify READ for a Writer:

Code: Select all

import java.nio.charset.*;
import java.nio.file.*;
import java.io.*;
public class C15 {
    public static void main (String...args){
        try{
            Path p = Paths.get("C:\\Users\\XXX\\Documents\\java\\certification\\1z0-804\\xxx\\abc.txt");
            BufferedWriter bw = Files.newBufferedWriter(p
                                                        ,Charset.forName("UTF-8")
                                                        ,new OpenOption[]{StandardOpenOption.READ});                                                         
            bw.write("abc");
            bw.close();
        }
        catch(java.io.IOException e) {
            e.printStackTrace();
        }
    }
}

Exception in thread "main" java.lang.IllegalArgumentException: READ not allowed
        at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source)
        at java.nio.file.Files.newOutputStream(Unknown Source)
        at java.nio.file.Files.newBufferedWriter(Unknown Source)
        at C15.main(C15.java:9)
Cheers

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests