Paul Taylor
Paul Taylor

Reputation: 13150

Why is Files.walkFileTree not reporting unable to access mounted drive

My Java code traverses the root directories of computer in order to create a folder tree (for serving as json for web application)

for (Path path : FileSystems.getDefault().getRootDirectories())
{
    MainWindow.logger.severe("Walking:"+path.getRoot());
    if(Files.isDirectory(path))
    {
        constructRootData(path);
        visitFolder = new VisitFolder(keys, depth);
        Files.walkFileTree(path, visitFolder);
    }
}

Log Output

01/03/2018 10.40.42:GMT:CreateFolderTree:start:SEVERE: Walking:C:\
01/03/2018 10.40.42:GMT:CreateFolderTree:start:SEVERE: Walking:D:\
01/03/2018 10.40.42:GMT:CreateFolderTree:start:SEVERE: Walking:E:\
01/03/2018 10.40.42:GMT:CreateFolderTree:start:SEVERE: Walking:Y:\
01/03/2018 10.41.03:GMT:CreateFolderTree:start:SEVERE: Walking:Z:\

I noticed that although it only traverse a depth of 1 it started taking considerably longer and I realised the problem was that Y:\ was mapped to a remote NAS that was actually disconnected from the network, and it was taking 20 seconds to realize that.

1> Is there something I can do to determine Y:\ is not accessible quicker.

2> Why doesn't Files.walkFileTree() actually throw an Exception about this, it clearly doesn't because if it did Z:\ would not get processed, nothing to indicate a problem gets logged either.

Upvotes: 1

Views: 103

Answers (0)

Related Questions