Using VSS, I've created a volume snapshot and can successfully access files on it:
C:\> type \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Users\Eric\Desktop\test.txt
test text 1/2
test text 2/2
When I try to access the same file from java using java.io.File
it works fine. However I am unable to convert it to a java.nio.file.Path
by calling toPath
like this:
File file = newFile(vssPath)
Path path = file.toPath()
Doing so results in an exception trace. This is a known issue for OpenJDK and I get the same result with java 1.8.91:
STACKTRACE:: java.nio.file.InvalidPathException: Illegal character [?] in path at index 2: \\? \GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Users\qa\Desktop\lock_full.txt
at sun.nio.fs.WindowsPathParser.nextSlash(Unknown Source)
at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
at sun.nio.fs.WindowsPath.parse(Unknown Source)
at sun.nio.fs.WindowsFileSystem.getPath(Unknown Source)
at java.io.File.toPath(Unknown Source)
Since I can't get a Path
there are certain APIs I'm unable to use, for example java.nio.channels.AsynchronousFileChannel
which can only be instantiated with a Path
.
Is there any alternative syntax for accessing the shadow copy file that won't run afoul of this JDK limitation? The OpenJDK ticket linked above recommends just omitting the long-UNC prefix (\\?
) but I haven't found any variation of this that seems to be legal. For example the following all fail:
C:\> type \\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Users\Eric\Desktop\test.txt
C:\> type \\Device\HarddiskVolumeShadowCopy1\Users\Eric\Desktop\test.txt
C:\> type \\HarddiskVolumeShadowCopy1\Users\Eric\Desktop\test.txt
If there's no variant path I can use to call toPath()
then is there some other way I could acquire a java.nio.file.Path
that doesn't run afoul of the parser limitation?