您可以通过调用Files.setOwner()方法来设置文件所有者。
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path;//from N o w J a v a . c o m 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"); /* 来 自* 时 代 J a v a - nowjava.com