package com.resolvethis.nio;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
public class MakeFileHidden {
public static void main(String[] args) {
try {
Path path = Paths.get("C:\Users\ITSAO\Documents\testfile.txt");
Boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden" , LinkOption.NOFOLLOW_LINKS);
if (hidden != null && !hidden){
Files.setAttribute(path, "dos:hidden" , Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
System.out.println("File is now hidden!");
}
}catch (IOException ex){
System.err.println("Things went wrong: " + ex.getMessage());
ex.printStackTrace();
}
}
}
// Occupy this block of code to hide the file that I want to choose but I want to know what method or how can I make it visible again?