Antwerkz, Inc.
5Feb/09Off

Changing the Current Directory

This entry is part 3 of 5 in the series Tips

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.

Series NavigationDealing with NullPointerExceptionsString Concatenation Options

Technorati Tags: , ,

Posted by admin

Comments (2) Trackbacks (0)
  1. 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.


Trackbacks are disabled.