Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What''s going on with file names??

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access a file in my home directory:

File f = new File("~/mydir/myfile");
When i try to open the file, I find that it tries to open a

mycurrentdir/~/mydir/myfile.

What am I doing wrong?

 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think '~' is interpreted by the shell. java.io.File does not interpret it.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly wrote:I think '~' is interpreted by the shell. java.io.File does not interpret it.


Correct. However you can obtain the home directory from the System property "java.home" (user.home?) and use that. It goes something like this:

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic