This behaviour is documented, albeit it is not very visible. You have to delve into the java.nio.file
package description to see, right at the end, that:
Unless otherwise noted, invoking a method of any class or interface in this package created by one provider with a parameter that is an object created by another provider, will throw ProviderMismatchException.
The reasons for this behaviour may not be obvious, but consider for instance that two filesystems can define a different separator.
There is no method in the JDK which will help you there. If your filesystems use the same separator then you can work around this using:
path1.resolve(path2.toString())
Otherwise this utility method can help:
public static Path pathTransform(final FileSystem fs, final Path path)
{
Path ret = fs.getPath(path.isAbsolute() ? fs.getSeparator() : "");
for (final Path component: path)
ret = ret.resolve(component.getFileName().toString());
return ret;
}
Then the above can be written as:
final Path localPath = pathTransform(localDir.getFileSystem(), zipPath);
Files.exists(localDir.resolve(localPath));
component
variable in the loop never used? And you forgot to set return type toPath
and add brackets afterisAbsolute()
andgetSeparator()
. – Carner