Example usage for java.io File canWrite

List of usage examples for java.io File canWrite

Introduction

In this page you can find the example usage for java.io File canWrite.

Prototype

public boolean canWrite() 

Source Link

Document

Tests whether the application can modify the file denoted by this abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) {
    String filePath = "C:/Text.txt";
    File file = new File(filePath);

    if (file.canWrite()) {
        System.out.println("writable");
    } else {//  w w w  . j  a  v  a2 s.c o m
        System.out.println("not writable");
    }
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/demo.txt");
    System.out.println(file.setReadOnly());
    System.out.println(file.canWrite());
}

From source file:MainClass.java

public static void main(String[] a) {
    File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");
    System.out.println(myFile.canWrite());
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/File/demo.txt");

    System.out.println(file.setReadOnly());
    System.out.println(file.canWrite());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("ReadOnly.txt");
    file.createNewFile();//from  ww  w.  j a  va 2s  .  c  o m
    file.setReadOnly();

    if (file.canWrite()) {
        System.out.println("writable!");
    } else {
        System.out.println("read only!");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("Writable.txt");
    file.createNewFile();/*from   www .  jav  a 2 s.  co  m*/
    file.setReadOnly();

    if (file.canWrite()) {
        System.out.println("File is writable!");
    } else {
        System.out.println("File is in read only mode!");
    }
    file.setWritable(true);
    if (file.canWrite()) {
        System.out.println("File is writable!");
    } else {
        System.out.println("File is in read only mode!");
    }
}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("C:/test.txt");

    boolean bool = f.setWritable(true, false);

    System.out.println(bool);/*from ww  w  . j a  v a 2  s .co m*/

    bool = f.canWrite();

    System.out.print(bool);

}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("test.txt");

    // set writable to false
    f.setWritable(false);//from w  w w. j a v a 2s.  co m

    // returns boolean
    boolean bool = f.canWrite();

    System.out.println("Can write to test.txt: " + bool);
}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("C:/test.txt");
    boolean bool = f.setWritable(true);

    System.out.println("setWritable() succeeded?: " + bool);

    bool = f.canWrite();

    System.out.print("Is file writable?: " + bool);

}

From source file:FileAttributesDemo.java

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();//from  w w  w  .java2s. c o m
    }
    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());
}