目录

如何获取目录是否隐藏?(How to get a directory is hidden or not?)

问题描述 (Problem Description)

如何获取目录是否隐藏?

解决方案 (Solution)

下面的示例演示如何使用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());
   }
}

结果 (Result)

上面的代码示例将产生以下结果(因为隐藏了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\\IoWiki7\\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
↑回到顶部↑
WIKI教程 @2018