File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Pulling up File Permissions using Java API ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pulling up File Permissions using Java API ???" Watch "Pulling up File Permissions using Java API ???" New topic

Pulling up File Permissions using Java API ???

Sarin Kuraganti

Joined: Sep 04, 2003
Posts: 24
Hi All,

I wanted to know whether Java provides any API to pull up each and every permission associated with a file.

For example: In Unix, a file has 3 sets of permissions as shown below:


Example: -rwxrwxrwx

r - for read
w - for write
x - for execute

There are some methods provided in, such as canRead() and canWrite(), which help in telling whether a file is readable or writable. But I did not find any API which tells whether a file is 'executable'. Also, I presume the methods above pull up the permissions pertaining to the owner of the file, but not for the group and others part of a Unix File's permissions.

Is there a way to pull up the read/write/executable permissions for all the 3 catergories namely, UserPermissions, GroupPermissions and Others'Permissions.

I appreciate your note on this and appreciate your time too.

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I don't think you can do this without native code. It wouldn't be hard to do the JNI for it, though.

The canRead() and canWrite() methods, as far as I know, return a flag indicating whether the Java program can read or write the file. That does not map directly to any of the three sets of permissions in Unix.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Sarin Kuraganti

Joined: Sep 04, 2003
Posts: 24
Hello Peter,

Thanks for the reply. Can you tell me exactly how to use JNI to invoke Unix Shell scripts? All I have seen is that JNI can be used to invoke C/C++ code, but could not find how to use JNI in conjunction with Shell scripts. Do you have any clue? Currently I have a script which pulls up the 'rwx' permissions of a file, I want to invoke this script from my java program to get things going. Can you suggest anything to fix this one?

BTW, nice pics on your website.

I agree. Here's the link:
subject: Pulling up File Permissions using Java API ???
It's not a secret anymore!