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

后端 未结 2 1920
南方客
南方客 2020-12-07 02:23

I just need to know the owner\'s name of a file on Mac using Java -- how can I go about getting it? Thanks!

2条回答
  •  旧巷少年郎
    2020-12-07 02:48

    This one is nasty. There is no standard method for getting the owner of a file (at least up to and including Java 6, which is the current production version for OSX). The easiest way right now is to use a ProcessBuilder to exec a call to stat with the name of the file as its argument, and then parse the result that will be returned on the standard output channel from the subprocess. Care must be taken when parsing the result because usernames on OSX might have spaces in.

    Alternatively, use JNI.

提交回复
热议问题