java - Working around access denied in a FileWalking Tree in Java7 -
the following simple code test files.walkfiletree()
method. however, folder /etc/ssl/private
, has these permissions (rwx--x---
), throws exception, when thought guarded if statement (if (permissions.equals("rwx--x---")
).
what doing wrong? in advance.
public static void main (string []args) throws ioexception, interruptedexception { files.walkfiletree(paths.get("/"), new walkingthething2()); } @override public filevisitresult previsitdirectory(path dir, basicfileattributes attrs) throws ioexception { posixfileattributeview posixview = files.getfileattributeview(dir, posixfileattributeview.class); posixfileattributes posixattr = posixview.readattributes(); string permissions =posixfilepermissions.tostring(posixattr.permissions()); if (permissions.equals("rwx--x---")) { return filevisitresult.skip_subtree; } return filevisitresult.continue; } @override public filevisitresult visitfile(path file, basicfileattributes attrs) throws ioexception { try{ system.out.println(file.getfilename()+" " +files.size(file)); return filevisitresult.continue; } catch(ioexception io){return filevisitresult.continue;} } }
the exception is: java.nio.file.accessdeniedexception: /etc/ssl/private
edit: solved overriding visitfilefailed
:
public filevisitresult visitfilefailed(path file, ioexception io) { return filevisitresult.skip_subtree; }
Comments
Post a Comment