• Post Reply Bookmark Topic Watch Topic
  • New Topic

to find the home directory in java  RSS feed

 
terry Kiernan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
terry Kiernan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
terry Kiernan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, does it work?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


will get your user home and append the extra file path.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!