aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 15665
    
  15

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What''s going on with file names??
 
Similar Threads
[CDATA question
File I/O prior to Java 1.5
File class questoin
UNIXhow to ensure files created in a directory automatically has group "w" permission
Select directory with JFileChooser