Almost every article I read told me that you cannot have chdir in Java. The accepted answer to this question says you cannot do this in Java.
However, here are some of the things 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)
The test class is used here:
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 it now and expect it to work the same on all platforms?
java filesystems chdir
Geo
source share