Click here to watch in Youtube :
https://www.youtube.com/watch?v=VuGAiQVhr2Q&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java IO (Java File - How to set the file permission) |
import java.io.File; public class FileDemo { public static void main(String[] args) { File file = new File("/home/start.sh"); System.out.println("Is Execute allow : " + file.canExecute()); System.out.println("Is Write allow : " + file.canWrite()); System.out.println("Is Read allow : " + file.canRead()); file.setExecutable(false); file.setReadable(false); file.setWritable(false); System.out.println("----------------------------------------"); System.out.println("Is Execute allow : " + file.canExecute()); System.out.println("Is Write allow : " + file.canWrite()); System.out.println("Is Read allow : " + file.canRead()); } }
import java.io.File; public class FileDemo1 { public static void main(String[] args) { File file = new File("/home/hello.sh"); /* * Marks the file or directory named by this * abstract pathname so that only read operations * are allowed. */ file.setReadOnly(); if (file.canWrite()) { System.out.println("This file is writable"); } else { System.out.println("This file is read only"); } /* * A convenience method to set the owner's write * permission for this abstract pathname. */ file.setWritable(true); if (file.canWrite()) { System.out.println("This file is writable"); } else { System.out.println("This file is read only"); } } }
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_file_permission_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_file_permission_App/JavaIODemo
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5edb9b935a4ef60d2a672d03f038390cd08d4eb7/BasicJava/JavaIODemo_file_permission_App/JavaIODemo/?at=master
See also:
No comments:
Post a Comment