file - check if a folder is readable in Java 1.6 -
i trying check if folder readable in java 1.6 following 2 manner:
1) using canread method of file class. it's readable time (canread() return true):
final file folder = new file("file.xml"); if(folder.canread()){ // file readable }else{ // file not readable!! }
2) using filepermission class , catch exception. catchs exception time (when folder readable or not):
try { filepermission filepermission = new filepermission(folder.getabsolutepath(), "read"); accesscontroller.checkpermission(filepermission); // file readable } catch (accesscontrolexception pace) { // file not readable !! }
i have found there issue between microsoft windows os , java 1.6 case.
bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6203387
have solution?
this quick , dirty,
file dir = new file("foo"); if (dir.exists()) { if (dir.listfiles() == null) { // directory not readable } }
all io errors handled inside of listfiles().
Comments
Post a Comment