Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-28
7
Medium Priority
?
688 Views
Last Modified: 2013-12-26
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
Comment
Question by:ombli
  • 4
  • 3
7 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 24255959
> 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
 
LVL 1

Author Comment

by:ombli
ID: 24257975
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
 
LVL 62

Accepted Solution

by:
gheist earned 500 total points
ID: 24258203
There is no instrumentation in JDK to detect symlinks or devices, or node link count - kind of java is platform neutral.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 1

Author Comment

by:ombli
ID: 24258322
Do you know if comparing the canonical path with the absolute one is a valid solution (just for detecting)?
0
 
LVL 62

Expert Comment

by:gheist
ID: 24258364
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
 
LVL 1

Author Comment

by:ombli
ID: 24258428
I need to walk through the directory tree and avoid recursivity due to symbolic links.
0
 
LVL 62

Expert Comment

by:gheist
ID: 24258459
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question