1. Introduction
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
Parameters:
- method does not take any parameter
Returns
- true - if file exists in the filesystem and application can read it
Throws
- SecurityException - when application do not have access to the file
3. Examples
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:
4. Conclusion
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.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}