Managing symbolic links : Paths « JDK 7 « Java
- Java
- JDK 7
- Paths
Managing symbolic links
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) throws Exception {
Path path1 = Paths.get("/home/docs/users.txt");
Path path2 = Paths.get("/home/music/users.txt");
System.out.println(Files.isSymbolicLink(path1));
System.out.println(Files.isSymbolicLink(path2));
Path path = Paths.get(new URI("C:/home/./music/users.txt"));
System.out.println("Normalized: " + path.normalize());
System.out.println("Absolute path: " + path.toAbsolutePath());
System.out.println("URI: " + path.toUri());
System.out.println("toRealPath (Do not follow links): "+ path.toRealPath(LinkOption.NOFOLLOW_LINKS));
System.out.println("toRealPath: " + path.toRealPath());
}
}
Related examples in the same category