提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
要检查文件的可访问性级别,请使用isReadable(),isWritable()和isExecutable()方法。
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption;/**N o w J a v a . c o m**/ import java.nio.file.Path; public class Main { public static void main(String[] args) { Path path = FileSystems.getDefault().getPath( "C:/folder1/folder2/folder4", "test2.txt"); boolean is_readable = Files.isReadable(path); boolean is_writable = Files.isWritable(path); boolean is_executable = Files.isExecutable(path); boolean is_regular = Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS); if ((is_readable) && (is_writable) && (is_executable) && (is_regular)) { System.out.println(