This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: user.dir property
- To: Kresten Krab Thorup <krab at eos dot dk>
- Subject: Re: user.dir property
- From: Jeff Sturm <jsturm at sigma6 dot com>
- Date: Sun, 12 Mar 2000 15:04:54 -0500
- CC: java-discuss at sourceware dot cygnus dot com
- Organization: sigma6
- References: <20000310103001.7995.qmail@sourceware.cygnus.com> <38CBB679.579F964D@eos.dk>
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