current user directory question
If the user.dir system property is changed using set property it seems to take effect. But if a file created in current working directory, the file is still cerated in the current working directory that originally existed. Thought ?
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String[],%20java.lang.String[],%20java.io.File) has been in the platform since 1.3.
Oops! Well, you learn something new every day.
when I needed a 'current directory' that worked in the JythonShell I wrote, I just set up the machinery in the application. It was internal and anything that needed the 'current directory' would reference that File instance.
leouser
The user.dir property is set at VM startup to be the working directory. You should not change this property or set it on the command-line. If you do, then you will see some inconsistent behaviour as there places in the implementation that assumes that the user.dir is the working directory and that it doesn't change during the lifetime of the VM. So out of curiousity, what problem are you looking at that requires you change user.dir? Are you looking to change the working directory (like chdir)?
Alan,
Someone came and asked me about this. What the person was looking for was changing the current working directory.
-Navin
I assume you know that changing the working directory of a multi-threaded application can be hairy. It would be interesting to know why this person needs this feature. Is it a case where they want to resolve relative paths against some directory other than the value of user.dir?
Alan,
He said he was dealing with some code that was reading/writing files in default working directory. On windows this is desktop, so all the files get written on the desktop. Which is why he wants to change the working directory. I told him to get hold of the source code and make required changes. Personally I think it is a bad idea to write to some default folder.
-Navin




The whole "current" directory concept isn't really suited to a multi-threaded environment, as Java programs very often are.
And it's not like you can't produce the same effect with a File for the current directory for the most part. About the only time it might be significant is when using Runtime.exec().
In fact, how about that? An optional working directory parameter for Runtime.exec() would probably eliminate the only valid argument for being able to change current directory in the JVM.