Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamically get home directory

 
S.Subhash Chandran
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get the current user's home directory dynamically? if the program is run in UNIX based systems it should return:
/home/subhash
if run on windows, it should return:
c:/documents and settings/subhash/My Documents
Thanks in advance!
 
S.Subhash Chandran
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code:
import java.util.*;
class UP{
public static void main(String arg[]){
Properties p = System.getProperties();
String uhome = (String)p.get("user.home");
System.out.println(uhome);
}
}
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks a little neater if you say:

You avoid the cast and possibly the need to import java.util (but you may need it for other parts of your program).
 
S.Subhash Chandran
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is neat David! Tnx!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!