• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 702
  • Last Modified:

How can I check a symbolic / soft link in a Linux like OS from a Java Command without using JNI?

Hi,

    I need to detect if a file or directory is or is not a symbolic/soft link. There is not any File.isLink() function in the java.io.File class. I have read on the internet solutions like comparing the canonical path with the absolute class but they are market like "this work on most of cases but not all". Do you know which ones are those exceptions?

    I can detect it by using JNI but I want my application to be platform independent. Any idea?

Thanks in advance.

Jorge.-
0
ombli
Asked:
ombli
  • 4
  • 3
1 Solution
 
gheistCommented:
> to be platform independent

Then why you try to cover only soft links - Windows NTFS junctions and lnk files should be of interest also...
0
 
ombliAuthor Commented:
Sure you're right but Is there any way of detecting it without using JNI? I mean, I can implement a isLink.so and a isLink.dll and detect the OS by using java system properties, but I really don't like this worarround since I get far from pure Java.

Thanks.
0
 
gheistCommented:
There is no instrumentation in JDK to detect symlinks or devices, or node link count - kind of java is platform neutral.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
ombliAuthor Commented:
Do you know if comparing the canonical path with the absolute one is a valid solution (just for detecting)?
0
 
gheistCommented:
It is valid solution on UNIX only - but it is not complete.
Why you try to detect symlinks? Use canonical name and forget about them. For example Windows java can use paths with slashes, and canonical name is with backslashes - and the result - you get symlinks your way everywhere.
0
 
ombliAuthor Commented:
I need to walk through the directory tree and avoid recursivity due to symbolic links.
0
 
gheistCommented:
Then your identification of symlinks is correct.
But you can compare paths to path list and omit repeated ones - more like platform neutral solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now