How to find or check hidden files in Java ?
we can check the file property is hidden or not and accordingly we can use that file in our application. isHidden() method is provided on file Class in Java which we will use to test this property.
Syntax of the method:
public static boolean isHidden(Path path) throws IOException
Here we pass the path of the file for which we want to test hidden property and it will return true if it’s a hidden file otherwise will get false value.
Here is complete code example of finding hidden file in Java, we are using file.isHidden() method to check whether a file is hidden or not.
import java.io.File; public class FileHiddenExample{ public static void main(String[] args)throws SecurityException ,IOException{ File file = new File("C:/HiddenTest.txt"); if (file.isHidden()) { System.out.println("This file is Hidden file: "); }else { System.out.println("File is not Hidden "); } } }
The isHidden() method is system dependent, on UNIX platform, a file is considered hidden if it’s name is begins with a dot symbol (.); On Microsoft Windows platform, a file is considered to be hidden, if it’s marked as hidden in the file properties.