1. Introduction
The canWrite() method from Java IO API tests whether the app can have write permission to the specified path.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- true - the application is allowed to write to the file; false otherwise.
Throws
- SecurityException - when we do not have access to the file
3. Examples
3.1. Check if the application can write to the file /tmp/frontbackend.txt
The file does not exist so canWrite()
method returns false. The output will be:
4. Conclusion
In this article, we presented canWrite() method from Java IO. If our application needs to check if it is allowed to write to a specified file this method is the easiest way to do that. Note that the result will be also false if the file does not exist.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}