Пример #1
0
 // do not make updateLastAccessed synchronized
 public static void updateLastAccessed(File file) {
   try {
     Files.setAttribute(
         file.toPath(), "lastAccessTime", FileTime.fromMillis(new Date().getTime()));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #2
0
  public void setAttrs(FileAttrs attrs) throws IOException {
    UserPrincipal posixOwner;
    GroupPrincipal posixGroup;
    Set<PosixFilePermission> posixPerms;
    UserPrincipalLookupService lookup;

    if (System.getProperty("os.name").startsWith("Windows")) {
      Files.setAttribute(this.path.toPath(), "dos:archive", attrs.getDosArchive());
      Files.setAttribute(this.path.toPath(), "dos:hidden", attrs.getDosHidden());
      Files.setAttribute(this.path.toPath(), "dos:readonly", attrs.getDosReadonly());
      Files.setAttribute(this.path.toPath(), "dos:system", attrs.getDosSystem());
    } else {
      lookup = this.path.toPath().getFileSystem().getUserPrincipalLookupService();

      posixOwner = lookup.lookupPrincipalByName(attrs.getPosixOwner());
      posixGroup = lookup.lookupPrincipalByGroupName(attrs.getPosixGroup());
      posixPerms = PosixFilePermissions.fromString(attrs.getPosixPermission());

      Files.setOwner(this.path.toPath(), posixOwner);
      Files.getFileAttributeView(this.path.toPath(), PosixFileAttributeView.class)
          .setGroup(posixGroup);
      Files.setPosixFilePermissions(this.path.toPath(), posixPerms);
    }
  }