• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

to find the home directory in java

 
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 ..
 
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
 
Bartender
Posts: 9559
12
Mac OS X Linux 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());
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, does it work?
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


will get your user home and append the extra file path.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!