SecureDirectoryStream可用于依赖更严格安全性的应用程序。
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /** * n o w j a v a . c o m 提 供 **/ import java.nio.file.SecureDirectoryStream; import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFilePermission; import java.util.Set; public class Main { public static void main(String args[]) throws IOException { Path path = Paths.get("home/docs"); SecureDirectoryStream<Path> sds = (SecureDirectoryStream) Files.newDirectoryStream(path); PosixFileAttributeView view = sds.getFileAttributeView(PosixFileAttributeView.class); PosixFileAttributes attributes = view.readAttributes();/* 来自 时 代 J a v a 公 众 号 - nowjava.com*/ Set<PosixFilePermission> permissions = att