分别使用setAttribute()和getAttribute()方法
import java.io.IOException;/*来 自 nowjava.com - 时代Java*/ 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 {/*来自 n o w j a v a . c o m*/ 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,