canWrite(): This method is available in the java.io.File class of Java.
Syntax:
boolean java.io.File.canWrite()
This method tests whether the application can modify the file denoted by this abstract pathname.
Parameters: NA
Returns: true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.
Throws:
1. SecurityException - If a security manager exists and its java.lang.SecurityManager.checkWrite(java.lang.String) method denies write access to the file.
Approach
Java
import java.io.File;public class FilecanWrite {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);System.out.println(file.canWrite());}}
Output:
false
No comments:
Post a Comment