tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > ReadOnly File

ReadOnly File 

The following example shows how to check whether the given file is read-only.

File Name  :  
com/bethecoder/tutorials/io/ReadOnlyFileTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.File;

public class ReadOnlyFileTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    
    File file = new File("C:\\file_ops.txt");
    
    if (file.canWrite()) {
      System.out.println(file + " is not a read-only file");
    else {
      System.out.println(file + " is a read-only file");
    }
    
    file = new File("C:\\readonly_file.txt");
    
    if (file.canWrite()) {
      System.out.println(file + " is not a read-only file");
    else {
      System.out.println(file + " is a read-only file");
    }
  }

}
   

It gives the following output,
C:\file_ops.txt is not a read-only file
C:\readonly_file.txt is a read-only file



 
  


  
bl  br