I would like to set a (unix) owner and group of a file created from Java. I would like something like this:
Path file = ...;
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-x---");
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
Files.createFile(file, attr);
-- it is an example how to set permissions, but I cannot find how to do the same with owner/group.
Please note that I'm not interested in changing the owner after the file is created (this has already been answered on SO [1] [2]), but when the file is created.
Motivation for this question is that I need to make sure that the file I'm creating is not modified by other users while I set proper owner and permissions.