欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

为文件设置只读属性 (ReadOnly),只读readonly,import java.

来源: javaer 分享于  点击 27308 次 点评:66

为文件设置只读属性 (ReadOnly),只读readonly,import java.


import java.io.File;import java.io.IOException;public class FileAttributesDemo {    public static void main (String[] args) throws IOException {        // Create a new file, by default canWrite=true,readonly=false        File file = new File (\"test.txt\");        if (file.exists ()) {            file.delete ();        }        file.createNewFile ();        System.out.println (\"Before. canWrite?\" + file.canWrite ());        // set to read-only, atau canWrite = false */        file.setWritable (false);        System.out.println (\"After. canWrite?\" + file.canWrite ());    }}//该片段来自于http://byrx.net
相关栏目:

用户点评