The following example will not throw a FileAlreadyExistsException:
@Test
public void testit() throws Exception {
Path osFile = Path.of("Hello.txt");
Files.deleteIfExists(osFile);
Files.writeString(osFile, "Hello World");
try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW))) {
System.out.println("oops");
}
try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW, READ))) {
System.out.println("oops");
}
}
If you specify Set.of(CREATE_NEW, WRITE) you will get the expected Exception
@Test
public void testit() throws Exception {
Path osFile = Path.of("Hello.txt");
Files.deleteIfExists(osFile);
Files.writeString(osFile, "Hello World");
try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW))) {
System.out.println("oops");
}
try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW, READ))) {
System.out.println("oops");
}
}
If you specify Set.of(CREATE_NEW, WRITE) you will get the expected Exception
- csr for
-
JDK-8263623 (fs) Files.newByteChannel(path, Set.of(CREATE_NEW, READ)) does not throw a FileAlreadyExistsException when the file exists
-
- Closed
-
- is cloned by
-
JDK-8241620 (zipfs) Files.newByteChannel(zipfile, Set.of(CREATE_NEW, READ)) does not throw a FileAlreadyExistsException when the file exists
-
- Open
-