3

Possible Duplicate:
How do I get the name of a file's owner in Java on OSX?

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.

Community
  • 1
  • 1
Roberto Linares
  • 2,215
  • 3
  • 23
  • 35
  • 2
    @Chris: But that question was specifically about Mac OS X, and the accepted answer was tailored to that OS. This question is specifically looking for a way that is *not* the way described in that accepted answer. – ruakh Jan 13 '12 at 02:35

1 Answers1

16

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".

ruakh
  • 175,680
  • 26
  • 273
  • 307