This sample code makes a file read only.

 import java.io.File;
public class ReadOnlyExp {
    public static void main(String[] args) {
        File file=new File("c:\\MyFile");
        file.setReadOnly();
    }
}