• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed with File.canRead()  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble getting File.canRead() to return true when I think it should be.
On my Solaris 8 system there should be an empty directory called:
/h/data/local/ME
In order to check if it exists, I have my program create the path to the directory like this:

The problem I'm having is that the directory does exist, and has universal read/write privileges, yet I keep getting an "AccessControlException:access denied" exception.
Does anyone have any idea what might be preventing my program from reading from this directory?
 
Vlad Patryshev
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about tempFile.isDirectory()? Does not it do all the necessary job?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what method are you executing which throws the exception? File.canRead(), or some other?
Try a succession of method attempts:
<code><pre>
System.out.println("file path: " + tempFile.getAbsolutePath();
System.out.println("exists: " + tempFile.exists());
System.out.println("is dir: " + tempFile.isDirectory());
System.out.println("can read: " + tempFile.canRead());
System.out.println("can write: " + tempFile.canWrite());
</pre></code>
This may give you more clues...
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File.canRead() (as shown in my original post) is the one that throws the exception.
What's confusing me is that the directory I'm testing for readability has 777 permissions: universal read/write/execute. It exists, anyone can read from it, so why can't the program I wrote? I'm getting ready to give my workstation the old heave-ho off the third floor landing...

Originally posted by Jim Yingst:
Exactly what method are you executing which throws the exception? File.canRead(), or some other?
Try a succession of method attempts:
<code><pre>
System.out.println("file path: " + tempFile.getAbsolutePath();
System.out.println("exists: " + tempFile.exists());
System.out.println("is dir: " + tempFile.isDirectory());
System.out.println("can read: " + tempFile.canRead());
System.out.println("can write: " + tempFile.canWrite());
</pre></code>
This may give you more clues...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!