Get user.dir as a symlink not resolved

Roger Riggs Roger.Riggs at Oracle.com
Tue Jun 21 14:28:38 UTC 2016


Hi Max,

The user.dir system property returns the value from the Unix 'getcwd' 
function which is defined
as the absolute pathname.

An absolute pathname would be preferred over a symbolic link which would 
need to be constantly
re-evaluated because it might be changed externally.  The absolute 
pathname is more stable.

I don't know of a simple reliable workaround that would work cross platform.

On some systems you might be able to query the environment for the 'PWD' 
value.
See System.getEnv("PWD"). (haven't tried it).

Roger



On 6/21/2016 4:50 AM, Wang Weijun wrote:
> I'm on a Mac inside /tmp, which is a symlink to /private/tmp.
>
> System.getProperty("user.dir") shows me "/private/tmp". Is there a way to get "/tmp" which is exactly what `pwd` return? I only like "/private/tmp" if I called "cd /private/tmp".
>
> Thanks
> Max
>



More information about the core-libs-dev mailing list