使用Files类的setOwner方法
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; /** * n o w j a v a . c o m 提 供 **/ import java.nio.file.Paths; import java.nio.file.attribute.FileOwnerAttributeView; import java.nio.file.attribute.UserPrincipal; import java.nio.file.attribute.UserPrincipalLookupService; public class Main { public static void main(String[] args) throws Exception { Path path = Paths.get("C:/home/docs/users.txt"); try { UserPrincipalLookupService lookupService = FileSystems.getDefault() .getUserPrincipalLookupService(); UserPrincipal userPrincipal = lookupService .lookupPrincipalByName("jennifer"); /* 来自 N o w J a v a . c o m*/ Files.setOwner(path, userPrincipal); FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.