The canWrite() method from Java IO API tests whether the app can have write permission to the specified path.
2. Method signature
- method does not take any parameter
- true - the application is allowed to write to the file; false otherwise.
- SecurityException - when we do not have access to the file
3.1. Check if the application can write to the file
The file does not exist so
canWrite() method returns false. The output will be:
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.