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.

Share and Enjoy:
  • Digg
  • Reddit
  • del.icio.us
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Technorati
  • email

Technorati Tags: , ,