5Feb/09Off
Changing the Current Directory
- Basic Thread Advice
- Dealing with NullPointerExceptions
- Changing the Current Directory
- String Concatenation Options
- String Concatenation Revisited
One of the more common requests I see online from beginners (and from a not-so-beginner just now) is how to change the current directory. This one is really simple, so here's a quick snippet and the output.
System.out.println(new File(".").getAbsolutePath());
System.setProperty("user.dir", System.getProperty("java.io.tmpdir"));
System.out.println(new File(".").getAbsolutePath());
And the output:
/Users/jlee/.
/tmp/.
See? Simple.
February 5th, 2009 - 18:21
Does this change pwd, or just how File’s string constructors build FS paths? I can see this producing weird and confusing results if you have native code that handles paths that’s not aware of the System property.
February 5th, 2009 - 18:23
I’m not sure how it’d affect JNI. People who use JNI deserve whatever pain they get.