CWD : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

CWD
CWD (Current Working Directory). In Windows, it is the directory that prints when you type CD (Change Directory) on the command line. It is the default directory for the File class if you don’t specify a fully qualified filename. In Java, it is the current directory at the time java.exe was invoked. You can’t change it on the fly, but you can determine what it is with:
// 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.


This page is posted
on the web at:

http://mindprod.com/jgloss/cwd.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\cwd.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[13.59.130.130]
You are visitor number