package com.javaniu; import java.io.File; import java.io.IOException; /** * 修改文件为只读权限 * * @author javaniu * */ public class MakeFileReadOnly { public static void main(String[] args) throws IOException { File file = new File("c:/file.txt"); // mark this file as read only, since jdk 1.2 file.setReadOnly(); if (file.canWrite()) { System.out.println("This file is writable"); } else { System.out.println("This file is read only"); } // revert the operation, mark this file as writable, since jdk 1.6 file.setWritable(true); if (file.canWrite()) { System.out.println("This file is writable"); } else { System.out.println("This file is read only"); } } }

1184719640 LV1
2021年8月11日
zhangweiooy LV1
2019年8月27日
15992634571 LV2
2017年6月27日
ybsharelife LV1
2016年8月10日
青红造了个白 LV11
2016年4月14日
小麻雀 LV1
2015年11月26日
Cumberfish LV1
2015年4月21日
wzg356 LV18
2015年1月3日
随波逐流 LV1
2014年12月1日
watfgzs LV21
2014年11月30日