使用Files.setAttribute()设置文件所有者
import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path;/** from n o w j a v a . c o m - 时 代 Java**/ import java.nio.file.Paths; 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"); try { owner = path.getFileSystem().getUserPrincipalLookupService(). lookupPrincipalByName("apress"); Files.setAttribute(path,