Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hidden files and File.list() returning null

835847Feb 26 2011 — edited Feb 27 2011
I wrote code to recursively search a file system from the root and return the full path and name of the file.

Problem:

I am using Windows 7 and the directory 'Documents And Settings' is hidden but is also inaccessible and causes any attempt to list() on that directory to return null.
// Grab the list of files and directories
filesAndDirs = dir.list();    <---------- is null because can not access ' Documents And Settings'
			
// Quick search of the list for our file
for (String element : filesAndDirs){   <------------------- null thrown here
   if (element.equals(searchName)){
      System.out.println("FILE FOUND");
      foundFlag = true;
      return new File(dir, element);
}
I would like to use fileAndDirs = null in order to know if the file I am searching for is never found.

When attempting to list() on a forbidden folder, is there a way to test if a folder is forbidden?

Edited by: Always Learning on Feb 26, 2011 1:18 PM

Edited by: Always Learning on Feb 26, 2011 1:23 PM

Edited by: Always Learning on Feb 26, 2011 1:25 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2011
Added on Feb 26 2011
9 comments
843 views