在 Java 中檢查檔案是否隱藏


java.io.File.isHidden() 方法用於檢查由抽象路徑名稱指定的檔案在 Java 中是否為隱藏檔案。如果由抽象路徑名稱指定的檔案已隱藏,則此方法返回 true,否則返回 false。

演示這一點的程式如下 -

示例

 線上演示

import java.io.File;
public class Demo {
   public static void main(String[] args) {
      try {
         File file = new File("demo1.txt");
         file.createNewFile();
         System.out.println("Is file hidden? " + file.isHidden());
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

上述程式的輸出如下 -

輸出

Is file hidden? false

現在讓我們理解上述程式。

java.io.File.isHidden() 方法用於檢查由抽象路徑名稱指定的檔案是否為隱藏檔案,並列印該方法返回的布林值。演示這一點的程式碼段如下 -

try {
   File file = new File("demo1.txt");
   file.createNewFile();
   System.out.println("Is file hidden? " + file.isHidden());
} catch(Exception e) {
   e.printStackTrace();
}

更新於: 30-Jul-2019

628 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.