Java File check if a file is writable

Description

Java File check if a file is writable

import java.io.File;

public class Main {
  public static void main(String[] args) {
    String filePath = "Main.txt";
    File file = new File(filePath);

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



PreviousNext

Related