Is there any method on a class from java.io, java.nio, commons-io, etc. that I can use to get the owner of a given file in my filesystem?
I really don't want to create a shell to execute an unix-only/windows-only command to get it. It would look awful and wouldn't be platform independent.
解决方案
Judging from the Javadoc, you should be able to do this:
java.nio.file.Files.getOwner(file.toPath())
(where file is an instance of java.io.File). Note that this requires Java 7. Also note that it will throw an UnsupportedOperationException on some platforms, because some file-systems, such as FAT32, have no concept of a file "owner".