| Author |
to find the home directory in java
|
terry Kiernan
Ranch Hand
Joined: Aug 23, 2008
Posts: 31
|
|
Hi , Does anyone know of a neat way to retieve a file X from anyones home diretory say you are running the java app in /net/partt/blah/projectwork your home dir is in /net/blah/user/dir/X the user can be anyone ... Anyone know a neat way to do this in java ? Help much appreciated ..
|
 |
Tom Johnson
Ranch Hand
Joined: May 11, 2005
Posts: 142
|
|
You can get the user directory using From there you can create a file object representing the target file and do whatever you want with it then, i.e. read it, parse it etc, using the java.io.File API. Hope this helps
|
<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
|
 |
terry Kiernan
Ranch Hand
Joined: Aug 23, 2008
Posts: 31
|
|
thanks tom, That helps but i am trying to get the file so say i want the string value to hold this value $HOME/.Xdir/file.cc ( the relative path name for the file) String UserHome = System.getProperty("user.home" + .Xdir/file.cc) But when i run this i get null , any ideas Thanks
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8291
|
|
There is no system property named "user.home.Xdir/file.cc", which is what you are passing to System.getProperty. First get the home directory from System.getProperty() then append whatever subdirectories and files you want after.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
terry Kiernan
Ranch Hand
Joined: Aug 23, 2008
Posts: 31
|
|
Joe, Is this what you mean ? StringBuffer strb = new StringBuffer (system.getproperty); strb.append (".Xdir/xfile.cc"); System.out.println (strb.toString());
|
 |
Thomas Thevis
Ranch Hand
Joined: Sep 02, 2008
Posts: 87
|
|
|
Well, does it work?
|
SCJP 5.0, SCJD in progress
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
will get your user home and append the extra file path.
|
Regards, Rene Larsen
Dropbox Invite
|
 |
 |
|
|
subject: to find the home directory in java
|
|
|