以下实例演示了使用 File 类的 file.setReadOnly() 和 file.canWrite() 方法来设置文件只读:
Main.java 文件
以上代码运行输出结果为:
true false