Copy directory while saving symbolic links using Java / IO API files

Is it possible to copy the contents of a directory using the Java I / O APIs and files while preserving existing symbolic links? I am working on a tool that must perform directory copy operations on various UNIX variants while maintaining existing symbolic links.

I would prefer to try this using the core Java SE libraries without resorting to Runtime.exec / ProcessBuilder to invoke the platform binary / bin / cp. IOUtils Apache Commons may not support this.

Recently, I will use Runtime.exec / ProcessBuilder!

UPDATE: I assume that I will use Runtime.exec / ProcessBuilder to call my own cp executable, as this is not possible using the core Java APIs or any of the Apache Commons libraries.

+5
source share
1 answer

Are you limited to Java versions <= 6?

Otherwise, you can look at http://docs.oracle.com/javase/tutorial/essential/io/links.html , in particular the sections Detecting a symbolic link and finding the target of a link.

From Java NIO.2 File System in JDK 7 :

API java.nio.file , UNIX - , Java.

+4

All Articles