Pre-requisites: Java File Handling
So far the operations using Java programs are done on a prompt/terminal which is not stored anywhere. But in the software industry, most of the programs are written to store the information fetched from the program. One such way is to store the fetched information in a file.
In this article, we will see how to open all the hidden files in the given path using Java
What is File Handling?
A file is a container which is used to store various types of information. Data is permanently stored in secondary memory by creating a file with a unique name. A file may consist of text, image or any other document.
Different Operations that can be performed on a file: There are various operations that can be performed on a file. They are:
- Creation of a new file.
- Opening an existing file.
- Reading from a file.
- Writing to a file.
- Moving to a specific location in a file.
- Closing a file.
Approach: All the above operations can be performed on the files which are visible when browsed through the directories. However, there may be cases where the files present in the directory are hidden and the data is securely stored in the hidden files. However, the files which are hidden can also be accessed using java. The IO package of java contains a special method named isHidden() whose return type is a boolean which returns true if the file is hidden and false if the file is not hidden. Apart from that, the java AWT package contains the Desktop class which has all the methods required to open, edit, browse the folders. Therefore, the idea to open the hidden files is to use the isHidden() method to check if the file is hidden or not and use open() method to open those hidden files.
Below is the implementation of the above approach:
Note: The above code cannot be run on the online IDE.
Output: Here, a text file with some data in it has been hidden in the “D:” directory. The working of the above program is as follows:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java program to merge contents of all the files in a directory
- Java program to List all files in a directory and nested sub-directories | Recursive approach
- Check if a File is hidden in Java
- Traversing directory in Java using BFS
- Hidden Form Field using Annotation | Java Servlet
- Moving a file from one directory to another using Java
- How to run java class file which is in different directory?
- Jar files in Java
- Compressing and Decompressing files in Java
- How to rename all files of a folder using Java?
- Working with JAR and Manifest files In Java
- Java Program to open the command prompt and insert commands
- Files size() method in Java with Examples
- Files isExecutable() method in Java with Examples
- Files isWritable() method in Java with Examples
- Files isReadable() method in Java with Examples
- Files delete() method in Java with Examples
- Files deleteIfExists() method in Java with Examples
- Java program to merge two files into a third file
- Files getFileStore() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.