Tutorialspoint examples

Learn java tutorial with examples for beginners online

check if file is writable java program

The canWrite() method of File class is used to check if file is writable java. It returns true if the specified file is writable else return false.


package com.tutorialspointexamples;
import java.io.File;
public class WritableFileTest {
  public static void main(String args[]){
      try {
     	 File file = new File("D:/Test files/newTest.txt");
     	 //Check the file is writable or read only
     	    System.out.println("File is writable.");
     	    System.out.println("File is read only.");
      } catch (Exception e) {


File is read only.

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status