Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I set the current working directory to a particular directory, such that subsequent file opens only need to only use relative file paths?

0
Posted

How do I set the current working directory to a particular directory, such that subsequent file opens only need to only use relative file paths?

0

Location: http://www.jguru.com/faq/view.jsp?EID=203366 Created: Sep 12, 2000 Modified: 2001-08-18 18:59:20.029 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Charles Chen (http://www.jguru.com/guru/viewbio.jsp?EID=137374 I seem to recall a time where setting the user.dir System property did this for you. However, that doesn’t seem to work any more (if it ever did). There is no standard way to do this, like a method of the File class or some such. The best you can do is to create a File object for the new “root” directory, then create new File objects passing this as the parameter to it: File root = new File(“/foo/bar”); File real = new File(root, “real”); Also, according to David Rees: Note that setting the “user.dir” in Java doesn’t change the working directory – it only seems to ;). All it really does is update the path that the methods getAbsolute* and getCanonical* work relative to. For instance if you start a program in Java in the

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.