The canRead() checks if the application can read the specified file. Note that this method similar to
canExecute() may return true even though the file does not have read permissions when we start JVM with special parameters.
2. Method signature
- method does not take any parameter
- true - if file exists in the filesystem and application can read it
- SecurityException - when application do not have access to the file
3.1. The program that checks if the file under
/tmp/frontbackend.txt is readable
If the file does not exists or application does not have permission to read it we will get the following output:
If the file
/tmp/frontbackend.txt exists and can be read by the application we will get:
In this article we presented
File.canRead() a method that checks if an application can read the file specified by pathname. Keep in mind that JVM can be started with special parameters that change the behavior of the applications, and files without reading permissions could be classified as readable.