Determine if a file can be written - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Determine if a file can be written

Demo Code

 
import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
    String filePath = "C:/Folder/ReadText.txt";
    File file = new File(filePath);
    if(file.canWrite())
    {//from  www  .j  a v  a2  s.c  o  m
      System.out.println("File " + file.getPath() +" can be written");
    }
    else
    {
      System.out.println("File " + file.getPath() +" can not be written");
    }
  }
}

Result


Related Tutorials