首页 > 编程语言 > 详细

2.2.5 NIO.2 Path 和 Java 已有的 File 类

时间:2016-01-06 15:23:28      阅读:82      评论:0      收藏:0      [点我收藏+]
NIO与IO交互
toPath() File -- Path
toFile() Path -- File

Demo:

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

public class PathAndFile {
    
    public static void main(String[] args) {
        
        File file = new File("/Users/jinxing/Documents/pathtest/path1");
        Path path = Paths.get("/Users/jinxing/Documents/pathtest/path1");
        
        File pathFile = path.toFile();
        Path filePath = file.toPath();
        
        System.out.println(pathFile.getName());
        System.out.println(filePath.getFileName());
        
    }

}

Ran As Java Application:

path1
path1

 

2.2.5 NIO.2 Path 和 Java 已有的 File 类

原文:http://www.cnblogs.com/springup/p/5105328.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!