Changing the current working directory in Java?

There is no reliable way to do this in pure Java. Setting the user.dir property via System.setProperty() or java -Duser.dir=… does seem to affect subsequent creations of Files, but not e.g. FileOutputStreams. The File(String parent, String child) constructor can help if you build up your directory path separately from your file path, allowing easier swapping. … Read more