Is it possible to copy directory contents using the Java I/O and File-related APIs while preserving existing symlinks? I am working on a tool that needs to perform "directory copy" operations on a variety of UNIX flavours while preserving existing symlinks.
I'd prefer to attempt this using the core Java SE libraries without resorting Runtime.exec/ProcessBuilder to invoke the platform's "/bin/cp" binary. Apache Commons' IOUtils doesn't appear to support this either.
My last resort will be to use Runtime.exec/ProcessBuilder!
UPDATE: I guess I'll be using Runtime.exec/ProcessBuilder to call out to the native "cp" executable since this doesn't seem to be possible using the core Java APIs nor any of the Apache Commons libraries.
Are you restricted to Java versions <= 6?
Otherwise you may want to look at http://docs.oracle.com/javase/tutorial/essential/io/links.html, specifically the sections Detecting a Symbolic Link and Finding the Target of a Link.
From The Java NIO.2 File System in JDK 7:
The java.nio.file API has full support for symbolic links based on the long-standing semantics of UNIX symbolic links -- something that Java developers have long requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With