public static String getPrefix(final String filename)
    {
        if (filename == null)
        {
            return null;
        }
        final int len = getPrefixLength(filename);
        if (len < 0)
        {
            return null;
        }
        if (len > filename.length())
        {
            return filename + UNIX_SEPARATOR;  // we know this only happens for unix
        }
        return filename.substring(0, len);
    }
public static String getPrefix ( final String filename ) { if ( filename == null ) { return null ; } final int len = getPrefixLength ( filename ) ; if ( len < 0 ) { return null ; } if ( len > filename . length ( ) ) { return filename + UNIX_SEPARATOR ; } return filename . substring ( 0 , len ) ; }
Gets the prefix from a full filename, such as <code>C:/</code>
or <code>~/</code>.
<p>
This method will handle a file in either Unix or Windows format.
The prefix includes the first slash in the full filename where applicable.
<pre>
Windows:
a\b\c.txt           --> ""          --> relative
\a\b\c.txt          --> "\"         --> current drive absolute
C:a\b\c.txt         --> "C:"        --> drive relative
C:\a\b\c.txt        --> "C:\"       --> absolute
\\server\a\b\c.txt  --> "\\server\" --> UNC

Unix:
a/b/c.txt           --> ""          --> relative
/a/b/c.txt          --> "/"         --> absolute
~/a/b/c.txt         --> "~/"        --> current user
~                   --> "~/"        --> current user (slash added)
~user/a/b/c.txt     --> "~user/"    --> named user
~user               --> "~user/"    --> named user (slash added)
</pre>
<p>
The output will be the same irrespective of the machine that the code is running on.
ie. both Unix and Windows prefixes are matched regardless.

@param filename  the filename to query, null returns null
@return the prefix of the file, null if invalid