1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Mark file or directory Read Only This Java example shows how set mark a particular file or directory as a read only using setReadyOnly method of Java File class. */ import java.io.*; public class MarkFileReadOnly { public static void main(String[] args) { //create file object File file = new File("C://FileIO//demo.txt"); /* * To mark a particular file or directory as a read only, use * boolean setReadyOnly() method of Java File class. * * This method returns true if the operation was successful. */ boolean blnMarked = file.setReadOnly(); System.out.println("Was file marked read only ?: " + blnMarked); //check whether file is readonly or not using canWrite method System.out.println("Is file writable ?: " + file.canWrite()); } } /* Output would be Was file marked read only ?: true Is file writable ?: false */ |
Add Comment