获取Owner属性值的两种方式---Owner

来源:互联网 发布:淘宝欠下贷款怎么协商 编辑:程序博客网 时间:2024/05/21 06:14
  • FileOwnerAttributeView.getOwner()
    Path path = Paths.get("F:/cn/icer/ws/client/Business.java");FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);try {String owner = foav.getOwner().getName();System.out.println(owner);} catch (Exception e) {e.printStackTrace();}


  • Files.getAttribute()
    Path path = Paths.get("F:/cn/icer/ws/client/Business.java");try {UserPrincipal owner = (UserPrincipal) Files.getAttribute(path, "owner:owner", LinkOption.NOFOLLOW_LINKS);System.out.println(owner.getName());} catch (Exception e) {e.printStackTrace();}

  • 文件所有者属性可以根据需要使用下列名称
    owner


0 0