Why is the user.dir system property working in Java?
Posted
by Geo
on Stack Overflow
See other posts from Stack Overflow
or by Geo
Published on 2009-08-05T18:05:32Z
Indexed on
2010/05/27
0:21 UTC
Read the original article
Hit count: 529
Almost every article I read told me that you can't have chdir in Java. The accepted answer to this question says you can't do it in Java.
However, here's some of the stuff I tried :
geo@codebox:~$ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
Here's a test class I'm using :
import java.io.*;
public class Ch {
public static void main(String[] args) {
System.out.println(new File(".").getAbsolutePath());
System.setProperty("user.dir","/media");
System.out.println(new File(".").getAbsolutePath());
}
}
geo@codebox:~$ pwd
/home/geo
geo@codebox:~$ java Ch
/home/geo/.
/media/.
Please explain why this worked. Can I use this from now on and expect it to work the same way on all platforms?
© Stack Overflow or respective owner