android - How to get File Permission Mode programmatically in Java -


I know that it is possible to change the permission mode of the file to be used:

Runtime .getRuntime (). Exec ("chmod 777 myfile"); .

This example sets the permission bit to 777 . Is it possible to set permission code on 777 using Java? Can this be done in every file?

The use of chmod in Android

For java platform dependent tasks such as chmod Although the original support is not supported, Android. Android provides access to some of these operations through Android. The FileUtils class is not part of the public SDK and is therefore not supported. Therefore, use it at your own risk:

  Public int chmod (file path, int mode) throws exception {class fileUtils = Class.forName ("android.os.FileUtils"); Method setpressions = fileUtils.getMethod ("setPermissions", String.class, int.class, int.class, int.class); Return (integer) setPermissions.invoke (empty, path. GateAbsolit path (), mode, -1, -1); } ... chmod ("/ foo / bar / hawk", 0755); ...   

context:

Comments