In this quick and simple article, you'll learn how to create a read only file or mark an existing file as read only. One way is to use the FileAttribute class of Java's NIO package to set file permissions. Another way is to use java.io.File class's setReadOnly or setWritable methods.