- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
File Permissions in java
The Java.io.FilePermission class represents access to a file or directory. It consists of a pathname and a set of actions valid for that pathname. Following are the important points about File Permission −
- The actions to be granted are passed to the constructor in a string containing a list of one or more comma-separated keywords. The possible keywords are "read", "write", "execute", and "delete".
- The code can always read a file from the same directory it's in (or a subdirectory of that directory); it does not need explicit permission to do so.
Program
The java.io.FileOutputStream implies(Permission p) method tests if this FilePermission object "implies" the specified permission.
import java.io.FilePermission; import java.io.IOException; public class FilePermissionDemo { public static void main(String[] args) throws IOException { FilePermission fp = null; FilePermission fp1 = null; FilePermission fp2 = null; FilePermission fp3 = null; boolean bool = false; try { // create new file permissions fp = new FilePermission("C://test.txt", "read"); fp1 = new FilePermission("C://test.txt", "write"); fp2 = new FilePermission("C://test1.txt", "read"); fp3 = new FilePermission("C://test.txt", "read"); // tests if implied by this object bool = fp.implies(fp1); // print System.out.println(bool); bool = fp.implies(fp2); System.out.println(bool); bool = fp.implies(fp3); System.out.print(bool); } catch(Exception ex) { // if an error occurs ex.printStackTrace(); } } }
Output
false false true
- Related Articles
- How to set file permissions in Java?
- File Permissions in C#
- Advanced File Permissions in Linux
- How to change file permissions in Python?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to check the permissions of a file using Python?
- Getting root permissions on a file inside of vi on Linux
- File Objects in Java
- Copying a File in java
- Deleting a File in java
- Set file attributes in Java
- MySQL permissions to view all databases?
- Setting Permissions with chown and chmod
- What are file operations in Java?
- Reading a Text file in java

Advertisements