|
ReadOnly File
The following example shows how to check whether the given file is read-only.
|
package com.bethecoder.tutorials.io;
import java.io.File;
public class ReadOnlyFileTest {
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("C:\\file_ops.txt");
if (file.canWrite()) {
System.out.println(file + " is not a read-only file");
} else {
System.out.println(file + " is a read-only file");
}
file = new File("C:\\readonly_file.txt");
if (file.canWrite()) {
System.out.println(file + " is not a read-only file");
} else {
System.out.println(file + " is a read-only file");
}
}
}
|
| |
It gives the following output,
C:\file_ops.txt is not a read-only file
C:\readonly_file.txt is a read-only file
|
|