
- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a directory is hidden or not in Java
Problem Description
How to get a directory is hidden or not?
Solution
Following 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
Advertisements