JavaQuick Tip: Finding Hidden Files Using Java

Quick Tip: Finding Hidden Files Using Java

Java Developer Tutorials

In this programming tutorial and quick tip, Java developers will learn how to find hidden files and uncover whether or not a file is hidden. Here is a quick Java code example of how to find a particular hidden file:

*/

import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.io.*;

public class ChkIfFileIsHidden
{
	public static void main(String args[])
	{
		ChkIfFileIsHidden chkIfFileIsHidden = new ChkIfFileIsHidden();
		chkIfFileIsHidden.proceed();
	}
	
	private void proceed()
	{
		try
		{
			Path currDirAndFile = Paths.get("./a.txt"); //Create a file a.txt and set its properties to hidden
			System.out.println("Files.isHidden(" + currDirAndFile + "): " + Files.isHidden(currDirAndFile));
		}catch(IOException ioe)
		{
			System.out.println("Exception: " + ioe);
		}
	}
}

/*

You can expect the following output if you run this Java code in your IDE or code editor:

[[email protected]]# java ChkIfFileIsHidden
Files.isHidden(.\a.txt): true

Read more Java programming tutorials and how-tos.

Latest Posts

Related Stories