如何在 Java 中获取目录是否隐藏
问题描述
如何获取目录是否隐藏?
解决方案
以下示例演示如何使用 File 类的 file.isHidden() 方法获取文件是否隐藏的事实。
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("C:/Demo.txt");
System.out.println(file.isHidden());
}
}
结果
上述代码示例将产生以下结果(因为 Demo.txt 被隐藏)。
True
以下是 Java 中目录是否隐藏的另一个示例
import java.io.File;
import java.io.IOException;
public class FileHidden {
public static void main(String[] args) throws IOException {
File file = new File("C:\Users\TutorialsPoint7\Desktop\abc.txt");
if(file.isHidden()) {
System.out.println("This file is hidden");
} else {
System.out.println("This file is not hidden");
}
}
}
上述代码示例将产生以下结果(因为 Demo.txt 被隐藏)。
This file is not hidden
java_directories.html

