使用FileOwnerAttributeView.setOwner()设置文件所有者
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /* *来 自 NowJava.com - 时代Java */ import java.nio.file.attribute.FileOwnerAttributeView; import java.nio.file.attribute.UserPrincipal; public class Main { public static void main(String[] args) { UserPrincipal owner = null; Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt"); /** n o w j a v a . c o m **/ FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class); try { owner = path.getFileSystem().getUserPrincipalLookupService().