集册 Java实例教程 从路径字符串创建路径

从路径字符串创建路径

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

447
从路径字符串创建路径

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 HardLink {

    /*

    Create a hard link:

    Windows:

    mklink /H newlinkfolder targetfolder

    linux:

    ln  targetfolder newlinkfolder

     */

    public static void main(String[] args) {

        Path link = FileSystems.getDefault().getPath("D:/intro/new");

        Path target = FileSystems.getDefault().getPath("C:/Users");


        try {

            //Files.createLink

            Files.createLink(link, target);

        } catch (IOException | UnsupportedOperationException e) {

            e.printStackTrace();

            if (e 
展开阅读全文