'How to handle FileSystemAlreadyExistsException?

How should you handle a FileSystemAlreadyExistsException when calling FileSystems.newFileSystem?

One way would be to use the already created FileSystem (getFileSystem​), but then you could run into problems when the original creator closes it while you are still using it.

In case there is no generic answer to this question, then what about ZipFileSystems? Let's say I want to create one for a zip file and I do not know and cannot control whether a FileSystem already exists for this specific zip file.

Is there a reliable way to handle a FileSystemAlreadyExistsException?



Solution 1:[1]

Try putting a try/catch block around the code that is causing the exception.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1