How To Hide A File In Java
In this tutorial, we will be discussing on how to hide a file in Java through an easy and simple program.
We will also show if the file is hidden or not.
The reason a few records and organizers are naturally set apart as covered up is on the grounds that, not at all like other information like your photos and reports, they’re not documents that you ought to change, erasing, or moving around.
If you don’t know how to hide a file in java then you are at the right place to solve your problem.
Hide A File In Java
Java has given a subsequent I/O framework called NIO (New I/O). Java NIO furnishes an alternate method for working with I/O than the standard I/O API’s. It is another I/O API for Java.
It bolsters a cushion situated, a channel-based methodology for I/O activities. With the presentation of JDK 7, the NIO framework is extended, giving improved help to document framework highlights and a record deal with. Because of the capacities upheld by the NIO record classes, NIO is broadly utilized in a document dealing with.
NIO was created to enable Java software engineers to actualize rapid I/O without utilizing the custom local code. NIO moves the time-taking I/O exercises like filling, specifically and depleting supports, and so forth once more into the working framework, in this manner takes into consideration an extraordinary increment in operational speed.
you can achieve your goal by:-
Java program to hide a file
import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; class HiddenFile { public static void main(String[] args) throws IOException { String Filepath = "C:/skr/important_documents.txt"; File file = new File(Filepath); if(file.isHidden()) System.out.println("File is hidden"); else System.out.println("File is visible"); Path p = Paths.get("C:/skr/important_documents.txt"); Files.setAttribute(p, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS); if(file.isHidden()) System.out.println("File is hidden"); else System.out.println("File is visible"); } }
output:-
File is visible File is hidden
This program also shows us if a file is hidden or not in Java.
Also read:
Leave a Reply