title: How to set file owner/group when creating a file in Java
body: <p>I would like to set a (unix) owner and group of a file created from Java. I would like something like <a href="http://www.java2s.com/Code/Java/JDK-7/CreatePosixFilePermissionsfromstringrwxrx.htm" rel="nofollow noreferrer">this</a>:</p>
  
  <pre><code>Path file = ...;
  Set&lt;PosixFilePermission&gt; perms = PosixFilePermissions.fromString("rwxr-x---");
  FileAttribute&lt;Set&lt;PosixFilePermission&gt;&gt; attr = PosixFilePermissions.asFileAttribute(perms);
  Files.createFile(file, attr);
  </code></pre>
  
  <p>-- it is an example how to set permissions, but I cannot find how to do the same with owner/group.</p>
  
  <p>Please note that I'm not interested in changing the owner <em>after</em> the file is created (this has already been answered on SO <a href="https://stackoverflow.com/q/13241967/2032064">[1]</a> <a href="https://stackoverflow.com/q/28829021/2032064">[2]</a>), but <em>when</em> the file is created.</p>
  
  <p>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.</p>