0

Symlink A is pointing to a symlink B. Symlink B is pointing to a target file C. While trying to get what symlink A is pointing using getCanonicalPath() I am getting the target C and not the intermediate link B. But my requirement is to get the intermediate link B.

I have searched a lot but couldn't get the expected result. Any help is very much appreciated. P.S: right now I could use only Java 6.

I shall explain my scenario bit clearer.

bash-3.2$ ls -ltr
drwxr-xr-x 8 user user 4096 Jan 29 22:34 jdk1.6.0_45
lrwxrwxrwx 1 user user 58 Jun 17 04:53 jdk6 -> jdk1.6.0_45
lrwxrwxrwx 1 user user 51 Jun 22 09:41 current -> jdk6

Code I tried:

File file="/path/to/current";<br/>
String target=file.getCanonicalPath();

Now my "target" string is coming as "jdk1.6.0_45"..since current points to jdk6 which inturn points to jdk1.6.0_45..But my requirement is to get what excatly current points to i.e) jdk6

This link has only how to get the end target and not the intermediate links..But that is what I want.Please help

Community
  • 1
  • 1
ayifos
  • 65
  • 1
  • 6
  • 1
    Please add a concrete example of what you've tried to do with some code. – avojak Jun 22 '16 at 16:06
  • 1
    I think with native Java 6 there is no way. Probably you can run some shell command. This may help: http://stackoverflow.com/questions/813710/java-1-6-determine-symbolic-links – PeterMmm Jun 22 '16 at 16:14

0 Answers0