File class canWrite()method example
Tests whether the application can modify the file
File class canWrite()method example. This example shows you how to use canWrite()method.This method Tests whether the application can modify the file denoted by this abstract pathname.
Here is the code:-
/**
* @Program that Tests whether the application can modify the file denoted by
this abstract pathname.
* CanWrite.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class CanWrite {
public static void main(String[] args) {
// Create a File object
File myFile = new File("/home/girish/Desktop/g.txt");
//Tests whether the application can modify the file
if (myFile.canWrite()) {
System.out.println(myFile.getAbsolutePath() + " is a Writable File");
} else {
System.out.println(myFile.getAbsolutePath() + " is not a Writable File");
}
}
} |
Output of the program:-
| /home/girish/Desktop/g.txt is a Writable File |
|