本文介绍了如何从文件元数据权限Java获取用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在整个给定文件中使用java检索用户名及其对该文件的权限?
Windows和Linux.

How can I, throughout a given file, using java, retrieve an user name and its permissions to that file?
Windows and Linux.

推荐答案

将于今年推出的Java 7将对此提供支持.现在,它以预发布格式提供.如果该级别的发布足以满足您的需求,则可以使用它.

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.

第一种方法是使用Java本机接口(JNI)编写与相关Windows和Linux调用接口的C代码.然后,您将编译C代码(这需要针对每个操作系统来完成,并且可能需要分别针对32位和64位体系结构来完成).然后需要将生成的编译后的代码添加到Java程序的库路径中,以便可以加载它.此选项非常有效,但也很复杂.

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.

第二个选项是使用Java本机访问(JNA).这允许编写与本机函数和结构匹配的Java方法和类. JNA在将本机库与您的Java代码之间编组在一起时发挥了很大的魔力.无需编写或编译任何C代码.这种方法的性能不如JNI,但在许多情况下,它的性能足够.我已经为64位系统的Linux和OS X实现了这种方法,这两种方法都依赖于POSIX,因此它们非常相似.我不知道Windows文件元数据的运行方式,但是我可以肯定地说它应该不会很难.

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.

这篇关于如何从文件元数据权限Java获取用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:38