jQuery in Action, 3rd edition
The moose likes Linux / UNIX and the fly likes What''s going on with file names?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "What Watch "What New topic
Author

What''s going on with file names??

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 157
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

Joined: Jun 01, 2010
Posts: 618
I think '~' is interpreted by the shell. java.io.File does not interpret it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17145
    
  27

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:


An IDE is no substitute for an Intelligent Developer.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 157
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What''s going on with file names??
 
It's not a secret anymore!