12:37 am - Monday May 1, 2017

Creating Program For Check modify or not of given File boolean canWrite()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This  Creating Program For Check modify or not of given File

EXAMPLE PROGRAM


import java.io.*;

public class FileCanWrite {

public static void main(String[] args) {

File f = null;

f = new File("Prop.xml");

f.setWritable(false);

boolean bool = f.canWrite();

System.out.println("The File Can Write:" + bool);

f.setWritable(true);

boolean bool1 = f.canWrite();

System.out.println("The File Can Write:" + bool1);

}

}

 

Output

 

The File Can Write:false

The File Can Write:true

Explanation

public boolean canWrite()

 

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

 

Returns:

   true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.

 

Throws:

   SecurityException – If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file.

BACK

Filed in: Z-A All Java Codes

Comments are closed.