2.2.5 NIO.2 Path 和 Java 已有的 File 类
生活随笔
收集整理的這篇文章主要介紹了
2.2.5 NIO.2 Path 和 Java 已有的 File 类
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
| 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?
轉(zhuǎn)載于:https://www.cnblogs.com/springup/p/5105328.html
總結(jié)
以上是生活随笔為你收集整理的2.2.5 NIO.2 Path 和 Java 已有的 File 类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实验四、主存空间的分配和回收模拟
- 下一篇: 关于java中的不可变类(转)