该File.isHidded()方法检查File对象所代表的文件是否为隐藏文件。隐藏的定义因操作系统而异。在基于UNIX的系统上,当文件名以句点字符('.')开头时,该文件被认为是隐藏的。在Windows操作系统上,如果文件已在文件系统中标记为隐藏,则认为该文件是隐藏的。
当且仅当根据基础平台的约定隐藏此对象表示的文件时,此File.isHidden()方法返回。trueFile
package org.nhooo.example.io;
import java.io.File;
import java.io.IOException;
public class FileHiddenExample {
public static void main(String[] args) throws IOException {
File file = new File("Hidden.txt");
file.createNewFile();
// 我们正在使用isHidden()方法检查文件是否
// 隐藏。
if (file.isHidden()) {
System.out.println("File is hidden!");
} else {
System.out.println("File is not hidden!");
}
}
}如果要在Windows操作系统中将文件属性设置为隐藏,则可以在以下示例中看到它:如何设置文件属性的值?