Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 646
Marcono1234 Avatar asked Apr 28 '19 16:04

Marcono1234


1 Answers

Sorry for being late here, but I just ran into this myself. There are several versions of the FileSystems.newFileSystem() call, some versions throw FileSystemAlreadyExistsException, some do not. I found that using the version that accepts a Path object did not throw the exception and allowed me to work around the issue I was having.

like image 92
Boulder_on Avatar answered Nov 15 '22 14:11

Boulder_on