Java如何确定路径名是否为目录?
要确定抽象路径名是否为目录,我们可以使用File.isDirectory()方法。这是示例代码。
package org.nhooo.example.io;
import java.io.File;
public class IsDirectoryExample {
public static void main(String[] args) {
//创建File的实例。
File file = new File("/home/foo/bar");
//通过调用检查抽象路径名是否为目录
//File类的isDirectory()方法。
if (file.isDirectory()) {
System.out.println("This file is a directory.");
} else {
System.out.println("This is just an ordinary file.");
}
}
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短