Java IO & NIO Java Java API
java.nio.file.Files
public static boolean isHidden(Path path) throws IOException
Checks whether or not a file is hidden.
path
true
package com.logicbig.example.files;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;public class IsHiddenExample { public static void main(String... args) throws IOException { Path tempFile = Files.createTempFile("test-file", ".txt"); boolean hidden = Files.isHidden(tempFile); System.out.println("file: " + tempFile); System.out.println("exits: " + Files.exists(tempFile)); System.out.println("hidden: " + hidden); }}
file: C:\Users\Joe\AppData\Local\Temp\test-file41471039271856387.txtexits: truehidden: false
package com.logicbig.example.files;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import java.nio.file.attribute.DosFileAttributeView;public class IsHiddenExample2 { public static void main(String... args) throws IOException { Path tempFile = Files.createTempFile("test-file", ".txt"); //on windows DosFileAttributeView dosFileAttributeView = Files.getFileAttributeView(tempFile, DosFileAttributeView.class); dosFileAttributeView.setHidden(true); //get new path to make sure hidden attribute persisted with file Path filePath = Paths.get(tempFile.toString()); boolean hidden = Files.isHidden(filePath); System.out.println("file: " + filePath); System.out.println("exits: " + Files.exists(filePath)); System.out.println("hidden: " + hidden); }}
file: C:\Users\Joe\AppData\Local\Temp\test-file8670368833568014699.txtexits: truehidden: true