can anyone tell me how to setOwner as well as the fileKey for the particular file........
i've retrieved the metadata information but can't able to set values.....

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.UserPrincipal;

/**
 *
 * @author user
 */
public class check1 {
    
 public static void main(String args[]) throws IOException
 {
 Path file = Paths.get("C:\\clock.avi"); 


/*try
{
UserPrincipal owner = file.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("sally");

Files.setOwner(file, owner);
}catch(SecurityException e){}
*/
       
    
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);



//PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class).readAttributes();
//System.out.println(attrs.owner());


System.out.println("creationTime: " + attr.creationTime());
System.out.println("owner: " + view.getOwner());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());

System.out.println("isDirectory: " + attr.isDirectory());
System.out.println("isOther: " + attr.isOther());
System.out.println("isRegularFile: " + attr.isRegularFile());
System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
System.out.println("size: " + attr.size());
System.out.println("fileKey: " + attr.fileKey());
    }
}

Recommended Answers

All 3 Replies

but i i'm not able to set the owner of the file

even this code is not working............but resulting in giving bugs

Path path = Paths.get("C:\\clock.avi"); 
     UserPrincipalLookupService lookupService =
         provider(path).getUserPrincipalLookupService();
     UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
     Files.setOwner(path, joe);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.