我做以下操作來獲取文件的所有者:錯誤嘗試使用UserPrincipal
How do I get the name of a file's owner in Java on OSX?
這裏是我的代碼:
private String getOwner(File f)
{
Path p = Paths.get(f.getAbsolutePath());
UserPrincipal owner = Files.getOwner(p);
return owner.getName();
}
我得到一個「無法找到符號」錯誤。那就是:
...$ javac Delete.java
Delete.java:38: error: cannot find symbol
UserPrincipal owner = Files.getOwner(p);
^
symbol: class UserPrincipal
location: class Delete
1 error
我知道錯誤的意思,我已經嘗試了幾種import語句:
java.security。*; (http://docs.oracle.com/javase/7/docs/api/)
java.nio.file.attribute; (http://docs.oracle.com/javase/7/docs/api/)
我甚至不得不問這個問題,但我不知道我會做錯什麼!
你確定你有'java 7'嗎? –
我很確定這意味着我有Java 7 ... javac -version/javac 1.7.0_06 – jacky
向我們展示您得到的確切完整的錯誤消息。 –