私はjava7ファイルAPIを使用しています。検索したファイルの所有者を設定し、所有者属性を変更できます。私のコードは
public static void main(String[] args){
Path zip=Paths.get("/home/ritesh/hello");
try{
FileOwnerAttributeView view
= Files.getFileAttributeView(zip,FileOwnerAttributeView.class);
UserPrincipalLookupService lookupService
=FileSystems.getDefaullt().getUserPrincipalLookupService();
UserPrincipal owner=null;
try{ owner =lookupService.lookupPrincipalByName("rashmi");}
catch(UserPrincipalNotFoundException e){System.out.println("User not found");}
view.setOwner(owner);
} catch (IOException e){
e.printStackTrace();}
}
このコードから、ファイルの所有者を設定できます。しかし、私のタスクは、ユーザー (rashmi) にファイルへの読み取りアクセス権を付与し、もう 1 人のユーザーに読み取り/書き込みアクセス権を付与することです。ユーザーに特定のアクセス権を付与する方法を教えてください。タスクを達成できるようにコードまたはリンクします。