JDK-6309963 : File.getOwner() to retrieve information about file ownership
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-11
  • Updated: 2010-04-02
  • Resolved: 2009-02-16
Related Reports
Duplicate :  
The class java.io.File surprisingly lacks a method named: getOwner

We can get the size, whether it's a directory, whether it's readable, whether it's writable, the file name, etc.  Why not the owner name?

The signature ought to be: public String getOwner();

One consideration is that the concept of file ownership differs from system to system, and is absent in some systems.  That's handlable.  

Of the systems that have file ownership, they all can retrieve a printable owner name.  On Unix where you can have multiple user names for the same user ID, I suggest making the user name returned be the first one found in the password file (or other user name lookup means).  If the user name cannot be found or is otherwise unsupported, then return the numerical user ID as a string.

If file ownership does not exist on the system at all, you can return null.  Since you're gauranteed to return a non-null String if the concept of file ownership does exist, then returning null is a clear indication that the concept of file ownership does not exist.

There might be a hypothetical case to be made for a system that supports multiple file owners.  I don't know of such a system, so it's probably much too pedantic a case.  Especially since I can't think of a good use for having multiple file owners.

EVALUATION As part of JSR203, a new file system API will likely be added. File ownership, permissions, and access to file attributes is an important goal for this API. *** (#1 of 1): [ UNSAVED ] ###@###.###