Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get parent directory path  RSS feed

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,

I have a file created as new File ("full path")

I want to display the full path of parent directory that the file is in.

I do a createdFile.getParent() but I get a null.

What is teh quickest way to display the path of the parent directory without tokenizing the createdFile.getAbsolutePath() ???

Thanks for your help.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getParent() method called on a File should return the directory the file is in (if it's a file) or the parent of the directory (if it's a directory and not the root directory) or null (if it's the root directory).

Were you really looking for something fast, or were you just confused by the results you got?
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both.. I thought getParent should work but didn't look like now Iknow why, didn't actually give the "full path" in the constructor argument. Didn't want to go thru the hassle of tokenizing and looping and recreating the path, so was asking.. Thanks alot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!