将文件或目录标记为只读
/* 来自 *N o w J a v a . c o m*/ import java.io.*; public class Main { public static void main(String[] args) { File file = new File("C://Folder//demo.txt"); boolean blnMarked = file.setReadOnly(); System.out.println("Was file marked read only ?: " + blnMarked); /** 时 代 J a v a 公 众 号 - nowjava.com **/ System.out.println("Is file writable ?: " + file.canWrite()); } }