How to get an user name from a file metadata permissions Java?
How can I, throughout a given file, using java, retrieve an us开发者_如何学Goer name and its permissions to that file?
Windows and Linux.Java 7, which will be coming out this year, will support this. It is available in a pre-release format now. If that level of release is sufficient for your needs you could use it.
Otherwise there are two different approaches you can take. Both involve interfacing with native libraries.
The first is to use Java Native Interface (JNI) to write C code that interfaces with relevant Windows and Linux calls. Then you will compile the C code (this will need to be done for each operating system, and potentially separately for 32bit and 64bit architectures). The resulting compiled code will then need to be added to your Java program's library path so that it can be loaded. This option is very performant, but also quite involved.
The second option is to use Java Native Access (JNA). This allows for writing Java methods and classes that match the native functions and structs. JNA does lots of magic to marshal between the native libraries and your Java code. There is no need to write or compile any C code. This approach is less performant than JNI, but in many situations it is sufficiently performant. I have implemented this approach for Linux and OS X for 64bit systems, both of which rely on POSIX so they are very similar. I do not know how Windows file metadata operates, but I'm reasonably certain it should not be much harder.
精彩评论