What's the easiest way to check if a java.nio.file.Path
is a path from the default file system?
I'm working with an older API that still uses java.io.File
but also allows to pass an java.net.URL
.
I've come up with two possible solutions but they don't seem clean to me:
Catching UnsupportedOperationException
when calling Path.toFile()
but then I would use exceptions for the normal program flow.
Call Path.toUri()
and check if the scheme is "file"
or null
pathInstance.getFileSystem().equals(FileSystems.getDefault())