0

I was wondering, how can I find the final destination of a file?

For example, if I write this path:

C:\JavaDir\2ndDir\file.txt

The path would be simple, but if I type, for example:

C:\JavaDir\2ndDir\3rdDir\..\file.txt

Now, I can see that the destination would be ...\2ndDir\file.txt, but how can I run a command to check the destination?

  • [this](http://stackoverflow.com/questions/1099300/whats-the-difference-between-getpath-getabsolutepath-and-getcanonicalpath) may help, java.io.File.getCanonicalPath() returns what your requirement is, I think – guleryuz Oct 08 '16 at 18:03
  • i dont understand your question – Don Cheadle Oct 08 '16 at 18:06
  • File.getCanonicalPath() worked just fine, thanks! –  Oct 08 '16 at 18:08

1 Answers1

0

What you want is the canonical path, which is unique for every single file. You basically just need to create a File object and run the getCanonicalPath() method to get what you want.

File f = new File(yourPath);
System.out.println(f.getCanonicalPath());

...checking for exceptions, yada yada.

BJ Black
  • 2,483
  • 9
  • 15