Java examples for File Path IO:File Operation
To check file accessibility level, using the isReadable(), isWritable(), and isExecutable() methods.
import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; 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("The checked file is accessible!"); } else {// w ww .j av a2s . c o m System.out.println("The checked file is not accessible!"); } } }