Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using $Home in java file api... wont work ?  RSS feed

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys : Im trying this, my application runs on *nix so it should be valid... (Im in OS X).

System.out.println(new File("$HOME").exists());


Its returning false. Does this mean that java cant use $HOME in getting a path ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's an environment variable defined by the shell.

You can supply it to the program on the command line, or set up a properties file that the program can use to fetch such values. But you can't use environment variables in file paths.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will add that for this specific case, there's a Java System property (System.getProperty("user.home")) that you can use to get the value of $HOME.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks~

PS is there a good unix hack for this ? Im not to good with OS tricks?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a Unix hack. System.getProperty("user.home") will work on Unix just as well as on Windows.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!