Is there any way to read/set Unix rights for a file and check if process has user/group/other rights in Java? I know it's not a problem with JNI, but I need cross-platform solution without JNI.
-
3You need a crossplatform solution to read unix file rights? Oh well, that seems problematic for some java unrelated reasons. If the information that java offers with the File API aren't enough you'll need to use some unix specific solution. The NIO File class in Jdk7 though supports both ACLs and Unix rights - but I don't see how that'd be portable.. you'll have to stick with the highlevel informationVoo– Voo2011-06-22 20:18:27 +00:00Commented Jun 22, 2011 at 20:18
-
1"Unix file rights" (permissions?) doesn't sound very "cross-platform"!Kerrek SB– Kerrek SB2011-06-22 20:18:48 +00:00Commented Jun 22, 2011 at 20:18
-
I think it's pretty clear that the author meant "across platforms that support Unix file modes" so that he didn't have to write JNI and compile a library for each platform he wanted to support.Edward Thomson– Edward Thomson2011-06-23 18:34:31 +00:00Commented Jun 23, 2011 at 18:34
Add a comment
|
3 Answers
This is going to be possible with Java 7, which is going to be released this summer, using the classes in the package java.nio.file.attribute. See the JDK 7 API documentation.
Java 6 and older do not have anything in the standard library to work with Unix file system rights.
So, by using the Java 7 API you won't need JNI but as Voo says it is ofcourse not going to be cross-platform, because Windows and other non-Unix systems do not support Unix file rights.
3 Comments
Voo
Java7 may support unix filerights, but the solution won't be any more portable than using JNI if you really need such low level information (after all you generally can't map Unix filerights to ACLs)
Ivan Mushketyk
If you can map Unix rights on Windows rights it should be possible to list Windows/Unix ACLs to a list of Unix rights.
vidstige
@Voo realize that with JNI you would need to rebuild the JNI parts for each unix type, e.g. Mac, Linux, Solaris and so on, so certainly this approach helps a great deal. The wording "cross platform" however is unfortunate as it brings the mind to e.g. Windows.