Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getAbsolutePath()  RSS feed

 
Ram Kas
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my program, I am tryint go find absolute path of a file.

So, my code is as follows:



interviews.txt is present on desktop. But, the method returns the current directory path.

So, what does getAbsolutePath() mean?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that a File object doesn't really represent a file; it represents a file path. There may or may not really be a file at that path.

If you create a File with nothing but a file name, then that path is relative to the working directory. So your code will always print the location of a file "interviews.txt" in the directory where the program was started -- whether or not a file exists in that location.
 
Ram Kas
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!