Setting owner of a file in java ( ver-7) in Windows XP SP2
<p>Here's the code:</p>

<pre><code>import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.FileSystems;
import java.lang.UnsupportedOperationException;
import java.io.IOException;

public class SetOwnerOfFile{
    public static void main(String args[]){
        Path path=Paths.get("c:\\demotext.txt");
        try{
            UserPrincipal owner=Files.getOwner(path);
            System.out.format("The owner of file is: %s%n",owner.getName());

            UserPrincipalLookupService lookupservice=FileSystems.getDefault().getUserPrincipalLookupService();
            Files.setOwner(path,lookupservice.lookupPrincipalByName("joe"));

            UserPrincipal newowner=Files.getOwner(path);
            System.out.format("Now the owner of file is: %s%n",newowner.getName());
        }
        catch(UnsupportedOperationException x){
            System.err.println(x);
        }
        catch(IOException x){
            System.err.println(x);
        }
    }
}
</code></pre>

<p><strong>Output:</strong>
<br>The owner of file is: \Everyone
<br>java.nio.file.attribute.UserPrincipalNotFoundException
<br><br>The program is throwing IOException. Does it mean my OS restricts modification of the owner of a file? If not, please suggest me some solution.</p>
