Page 1 of 1

Creates a file and sets it to read-only -- Java

Posted: Wed Apr 11, 2012 9:26 am
by Nipuna

Code: Select all

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 ());
    }
}


Re: Creates a file and sets it to read-only -- Java

Posted: Wed Apr 11, 2012 6:31 pm
by SevenZero
Very nice Nipuna. Keep up the good work.

Re: Creates a file and sets it to read-only -- Java

Posted: Wed Apr 11, 2012 9:44 pm
by Nipuna
Thank you,

But these codes are not my ones, I found them online. You know if these are mine, I would have yelled so many thing that I did when I was coding it :)