File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What''s going on with file names??

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • 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
  • 0
  • 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: 17622
39
Android Eclipse IDE Linux
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic