How to get a directory is hidden or not?
SolutionFollowing example demonstrates how to get the fact that a file is hidden or not by using file.isHidden() method of File class.
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
The above code sample will produce the following result (as Demo.txt is hidden).
True
The following is an another example of directory is hidden or not in 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\\TutorialsPoint7\\Desktop\\abc.txt"); if(file.isHidden()) { System.out.println("This file is hidden"); } else { System.out.println("This file is not hidden"); } } }
The above code sample will produce the following result (as Demo.txt is hidden).
This file is not hidden
java_directories.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4