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?
+1
A:
System.getProperty("user.home"); gets you the user's home directory.
Asaph
2009-09-26 23:36:57
how would i be able to save that as a variable? is it a string?
Lonnie Ribordy
2009-09-26 23:42:00
Yes. It returns a String.
Asaph
2009-09-26 23:45:04
thankyou very much for this answer =]
Lonnie Ribordy
2009-09-26 23:46:07
@Asaph. Changing the "user.home" property does not properly change the user's home directory. Read the javadoc for File.getAbsolutePath carefully.
Stephen C
2009-09-27 03:46:48
@Stephen C. I never suggested changing "user.home". I only mentioned getProperty() in reference to "user.home". Furthermore, the documentation you mentioned located at http://java.sun.com/javase/6/docs/api/java/io/File.html#getAbsolutePath() makes mention of "user.dir" but not "user.home".
Asaph
2009-09-27 04:01:52
@Asaph: my mistake ... I really thought we were talking about "user.dir" rather than "user.home".
Stephen C
2009-09-27 15:21:51