###前提・実現したいこと
javaでLinux環境で作成したディレクトリの所有者を変更したい。
作成すると所有者がtomcatになるが、これを任意の所有者名に変更したいと思っています。
以下のソースでできることが分かりましたが、名称を設定することができずに困っています。
###該当のソースコード
java
1File dir = new File("/usr/local/test/1"); 2dir.mkdirs(); 3Path dirPath = Paths.get(dir.getAbsolutePath()); 4UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); 5UserPrincipal newOwner = lookupService.lookupPrincipalByName("testOwner"); 6Files.setOwner(dirPath, newOwner);
上記ソースを実行すると、UserPrincipal newOwner = …の行で
java.nio.file.attribute.UserPrincipalNotFoundException
が発生します。
setOwnerの引数のnewOwnerにはUserPrincipal型の値を渡す必要があるのですが、任意の所有者名を設定する方法が分かりません。
お手数ですが、よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー