1:39 pm - Tuesday August 21, 2018

To check permission in file using FilePermission

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 tutorial explains how To check permission in file using FilePermission,this method is used to check that our application can have access to read the file or not. Here is an example of checking a file is read only in Java.


import java.io.FilePermission;

public class FilePermission

{

	public static void main(String[] args)

	{

		boolean bool = false;

		FilePermission f1 = new FilePermission(
				"/home/mathan/Documents/abcd.txt", "read");

		FilePermission f2 = new FilePermission(
				"/home/mathan/Documents/abcd1.txt", "read");

		FilePermission f3 = new FilePermission(
				"/home/mathan/Documents/abcd.txt", "write");

		FilePermission f4 = new FilePermission(
				"/home/mathan/Documents/abcd.txt", "read");

		bool = f1.equals(f2);

		System.out.println(bool);

		bool = f1.equals(f3);

		System.out.println(bool);

		bool = f1.equals(f4);

		System.out.print(bool);

	}

}

Output

 

    false

    false

    true

BACK

Filed in: Java Examples

Comments are closed.