File: setWritable(boolean writable) : File « « Java by API

File: setWritable(boolean writable)



public class Main {

  public static void main(String[] args) throws IOException {
    // Create a new file, by default canWrite=true,
    boolean readonly = false;
    File file = new File("test.txt");
    if (file.exists()) {
    System.out.println("Before. canWrite?" + file.canWrite());

    // set to read-only, atau canWrite = false */
    System.out.println("After. canWrite?" + file.canWrite());


Related examples in the same category

3.File: separatorChar File(String name) File(URI uri) File(String parent, String child)
7.File: canRead()
8.File: canWrite()
9.File: createNewFile()
10.File: createTempFile(String prefix, String suffix)
11.File: delete()
12.File: deleteOnExit()
13.File: exists()
14.File: getAbsoluteFile()
15.File: getAbsolutePath()
16.File: getCanonicalPath()
17.File: getFreeSpace()
18.File: getName()
19.File: getParent()
20.File: getParentFile()
21.File: getPath()
22.File: getTotalSpace()
23.File: getUsableSpace()
24.File: isAbsolute()
25.File: isDirectory()
26.File: isFile()
27.File: listFiles()
28.File: isHidden()
29.File: lastModified()
30.File: length()
31.File: list()
32.File: listFiles(FilenameFilter filter)
33.File: listRoots()
34.File: mkdir()
35.File: mkdirs() (Creates a directory including any parent directories)
36.File: renameTo(File newFile)
37.File: setLastModified(long time)
38.File: setReadOnly()
39.File: toURI()
40.File: toURL()