By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
Ok. So when I change the current user directory, why do the files still get written to the directory that was being used before I changed it?
I would like to write to C:/ThinkingInJava/src/io/ but this always writes to C:/ThinkingInJava. Am I doing something wrong in the following code?
user.dir is set to the Java process' current working directory when Java starts up. You can read the value of this property, but there's no reason to change it. Changing this property doesn't change the current working directory -- there's no way to do that.
To write to a subdirectory of the current directory, you can pass a relative path to the FileOutputStream constructor rather than a plain filename. [ November 28, 2005: Message edited by: Ernest Friedman-Hill ]