tags:

views:

64

answers:

2

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
how would i be able to save that as a variable? is it a string?
Lonnie Ribordy
Yes. It returns a String.
Asaph
thankyou very much for this answer =]
Lonnie Ribordy
@Asaph. Changing the "user.home" property does not properly change the user's home directory. Read the javadoc for File.getAbsolutePath carefully.
Stephen C
@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
@Asaph: my mistake ... I really thought we were talking about "user.dir" rather than "user.home".
Stephen C
A: 

You get the current working directory, but not change it.

daveb