标签:
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