This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 145
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: 15962
    
  19

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:


Customer surveys are for companies who didn't pay proper attention to begin with.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Thanks!
 
Consider Paul's rocket mass heater.
 
subject: What''s going on with file names??
 
Similar Threads
Select directory with JFileChooser
[CDATA question
File I/O prior to Java 1.5
UNIXhow to ensure files created in a directory automatically has group "w" permission
File class questoin