Making a file read-only

Use the method setReadOnly in the File class. Notice that there is no method to determine whether a file is read-only or not, neither is there a method to undo the setReadOnly operation:

public class Main {
   public static void main(String[] args) {
      File file = new File("");
      boolean status = file.setReadOnly(); 
      System.out.println(file + " " + (status ? "":"un") + "successfully set to read-only");

When you execute (Windows DOS-prompt) attrib, you’ll see:

  A    R     MAIN~1.JAV