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)