集册 Java实例教程 检查路径是否为符号链接

检查路径是否为符号链接

欢马劈雪     最近更新时间:2020-01-02 10:19:05

521
检查路径是否为符号链接

import java.io.IOException;

import java.nio.file.FileSystems;//时 代 J     a    v  a - nowjava.com

import java.nio.file.Files;

import java.nio.file.Path;


public class Main {

  public static void main(String[] args) {


    Path link = FileSystems.getDefault().getPath("test");

    Path target = FileSystems.getDefault().getPath("C:/folder1/photos",

        "my_winner.jpg");


    try {

      Boolean link_isSymbolicLink_2 = (Boolean) Files.getAttribute(link,

          "basic:isSymbolicLink");

      Boolean target_isSymbolicLink_2 = (Boolean) Files.getAttribute(target,

          "basic:isSymbolicLink");

          /**
           from
          * nowjava.com - 时  代  Java 
          **/

      System.out.println(link.toString() + " is a symbolic link ? "

          + link_isSymbolicLink_2);

      System.out.println(target.toStrin
展开阅读全文