The following example will not throw a FileAlreadyExistsException:
@Test
public void zipFAETest(final Map<String, String> env,
final int compression) throws Exception {
Path zipFile = generatePath(HERE, "test", ".zip");
Files.deleteIfExists(zipFile);
Entry e0 = Entry.of("Entry-0", compression, THE_SLAMS);
zip(zipFile, env, e0);
// Validate that a FileAlreadyExistsException is thrown
try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env)) {
assertThrows(FileAlreadyExistsException.class, () ->
Files.newByteChannel(zipfs.getPath(e0.name), Set.of(CREATE_NEW)));
}
Files.deleteIfExists(zipFile);
}
If you specify Set.of(CREATE_NEW, WRITE) you will get the expected Exception
@Test
public void zipFAETest(final Map<String, String> env,
final int compression) throws Exception {
Path zipFile = generatePath(HERE, "test", ".zip");
Files.deleteIfExists(zipFile);
Entry e0 = Entry.of("Entry-0", compression, THE_SLAMS);
zip(zipFile, env, e0);
// Validate that a FileAlreadyExistsException is thrown
try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env)) {
assertThrows(FileAlreadyExistsException.class, () ->
Files.newByteChannel(zipfs.getPath(e0.name), Set.of(CREATE_NEW)));
}
Files.deleteIfExists(zipFile);
}
If you specify Set.of(CREATE_NEW, WRITE) you will get the expected Exception
- clones
-
JDK-8241619 (fs) Files.newByteChannel(path, Set.of(CREATE_NEW, READ)) does not throw a FileAlreadyExistsException when the file exists
-
- Resolved
-