setWritable(boolean): This method is available in the java.io.File class of Java.
Syntax:
boolean java.io.File.setWritable(boolean writable)
This method takes one argument. This method is a convenient method to set the owner's write permission for this abstract pathname.
Parameters: One parameter is required for this method.
writable: If true, sets the access permission to allow write operations; if false disallow write operations.
Returns: true if and only if the operation succeeded.
Throws:
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 FilesetWritable {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);boolean writable = true;System.out.println(file.setWritable(writable));}}
Output:
true
No comments:
Post a Comment