集册 Java实例教程 将文件或目录标记为只读

将文件或目录标记为只读

欢马劈雪     最近更新时间:2020-01-02 10:19:05

427
将文件或目录标记为只读
/* 
 来自 
*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());

  }

}