This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: user.dir property


Kresten Krab Thorup wrote:
> I'm trying to set the property user.dir and thereby effectively cd'ing
> to a given directory.  The following piece of code tries do do that, but
> fails on JDK1.2.2.  The code does the following
> 
> create file "/tmp/foo.bar"
> set user.dir = "/tmp"
> read "foo.bar"
> 
> Obviously, this is only interesting if the original value of "user.dir"
> is different from "/tmp".
> 
> The question is if this ought to be possible. As I read the javadoc for
> java.lang.File, it seems that it should.

I don't think there is a way to change the current directory of a Java
VM, at least without resorting to native code.

System properties are set by the VM during initialization, and
apparently never re-examined.  That's how libgcj works, and how Sun's
JDK empirically seems to work.  Effectively, system properties are
read-only.  It is probably a bug in the Java core API that they can be
changed by user code at all.

I remember a discussion years ago on advanced-java about this very
topic.  One of the Sun engineers suggested at the time that chdir() was
not supported in JDK 1.0 because its behavior is a little unpredictable
in a multithreaded environment.  In some thread models a chdir() would
affect all VM threads, in others it would affect only the calling
thread.  I suppose not supporting chdir() at all is an easy way to avoid
the problem...

--
Jeff Sturm
jsturm@sigma6.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]