To check if file is hidden in java, we use java.io.File API’s isHidden() method. In this post we will see example of how we use isHidden method in code.
Example : Check If File is Hidden
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.kscodes.sampleproject; import java.io.File; public class FileHiddenExample { public static void main(String[] args) { File file = new File("C:\\kscodes\\work\\test.txt"); if(file.isHidden()){ System.out.println("File test.txt is marked as Hidden"); }else{ System.out.println("File test.txt is NOT Hidden"); } } } |
Please Note
File.isHidden() works differently on windows and unix.
Please see the details at the java doc –
1. File isHidden()