Files isHidden() method in Java with Examples
Last Updated :
29 Jul, 2019
isHidden() method of java.nio.file.Files help us to check whether or not a file is hidden. This method return true if the file is considered hidden else it returns false. The exact definition of hidden is platform or provider dependent.
On UNIX, for example, a file is considered to be hidden if its name begins with a period character (‘.’). On Windows, a file is considered hidden if it isn’t a directory and the DOS hidden attribute is set. Depending on the implementation this method may require to access the file system to determine if the file is considered hidden.
Syntax:
public static boolean isHidden(Path path)
throws IOException
Parameters: This method accepts a parameter path which is the path to the file to check.
Return value: This method returns true if the file is considered hidden.
Exception: This method will throw following exceptions:
-
IOException: if an I/O error occurs
- SecurityException: In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
Below programs illustrate isHidden(Path) method:
Program 1:
import java.io.IOException;
import java.nio.file.*;
public class GFG {
public static void main(String[] args)
{
Path path
= Paths.get(
"D:\\GIT_EWS_PROJECTS\\logger"
+ "\\src\\logger"
+ "\\GFG.java" );
boolean result;
try {
result = Files.isHidden(path);
System.out.println( "File " + path
+ " is Hidden = "
+ result);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
|
Output:
Program 2:
import java.io.IOException;
import java.nio.file.*;
public class GFG {
public static void main(String[] args)
{
Path path
= Paths.get(
"D:\\User Aman\\"
+ "Documents\\MobaXterm\\"
+ "\\ArrayList.docx" );
boolean result;
try {
result = Files.isHidden(path);
System.out.println( "File " + path
+ " is Hidden = "
+ result);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
|
Output:
Reference: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Files.html#isHidden(java.nio.file.Path)
Share your thoughts in the comments
Please Login to comment...