如何创建java.nio.Path?
以下代码段显示了如何创建Path。中的Path(java.nio.Path)interface表示文件系统中的某个位置,例如C:/Windows/System32或/usr/bin。
要创建一个Path我们可以使用的java.nio.Paths.get(Stringfirst,String...more)方法。在下面,您可以看到如何Path仅通过传递first字符串以及通过传递first字符串和一些varargs字符串来创建a。
package org.nhooo.example.io;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class PathCreate {
public static void main(String[] args) {
//创建一个表示Windows安装位置的路径。
Path windows = Paths.get("C:/Windows");
//检查路径是否代表目录。
if (Files.isDirectory(windows)) {
//做点什么
}
//创建一个表示Windows程序安装位置的路径。
Path programFiles = Paths.get("C:/Program Files");
Files.isDirectory(programFiles);
//创建一个表示notepad.exe程序的路径
Path notepad = Paths.get("C:/Windows", "System32", "notepad.exe");
//检查路径是否代表可执行文件。
if (Files.isExecutable(notepad)) {
//做点什么
}
}
}
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短