in windows batch and and bash scripts there is %USERPROFILE% and ~, is there a command that works the same in java that will allow me to switch to the users home directory?
2 Answers
System.getProperty("user.home"); gets you the user's home directory.
4 Comments
Stephen C
@Asaph. Changing the "user.home" property does not properly change the user's home directory. Read the javadoc for File.getAbsolutePath carefully.
Asaph
@Stephen C. I never suggested changing "user.home". I only mentioned getProperty() in reference to "user.home". Furthermore, the documentation you mentioned located at java.sun.com/javase/6/docs/api/java/io/… makes mention of "user.dir" but not "user.home".
Stephen C
@Asaph: my mistake ... I really thought we were talking about "user.dir" rather than "user.home".
new File("").