Java examples for File Path IO:DOS File
Use setAttribute() and getAttribute() methods, respectively
import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.DosFileAttributes; public class Main { public static void main(String[] args) { DosFileAttributes attr = null; Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt"); //setting the hidden attribute to true try {/*from w w w.ja va2s . c om*/ Files.setAttribute(path, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS); } catch (IOException e) { System.err.println(e); } //getting the hidden attribute try { boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden", LinkOption.NOFOLLOW_LINKS); System.out.println("Is hidden ? " + hidden); } catch (IOException e) { System.err.println(e); } } }
DOS attributes can be acquired with the following names:
The generally accepted form is [view-name:]attribute-name.
The view-name is dos.