// Getting the CWD: Current Wording Directory // namely the current directory when java.exe was invoked. // It cannot be changed on the fly. final String cwd = new File( "." ).getCanonicalPath(); // Which may or may not be the same as: final String userDir = System.getProperty( "user.dir" );You can of course spawn a script to a command shell that would be able change the CWD inside itself, but not for the spawning Java app.
You can fake a CWD by maintaining your own CWD variable and expanding all relative filenames to absolute yourself.
The catch is, a Java program cannot dynamically change the CWD. The closest it could to that is spawn command scripts with embedded CD commands, that change on the local CWD within the script. It is odd that code implementing scripts can change the CWD, but not Java. I gather Java’s designers figured that you could not could on every possible OS (Operating System) permitting you to change the CWD. They could not thus safely built it in as a WORA (Write Once, Run Anywhere) feature.
|
|
available on the web at: |
http://mindprod.com/jgloss/cwd.html |
optional Replicator mirror
|
J:\mindprod\jgloss\cwd.html | |
![]() |
Please email your
feedback for publication,
letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear
wording, broken/redirected link reports, suggestions to improve this page or comments to
Roedy Green :
| |
| Blog | Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[54.224.79.93] |
|
| Feedback | You are visitor number 14,541. | |