Advertisement
Guest User

Untitled

a guest
May 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public class FileUtil {
  2. public static void chmod(String path, int mode) throws Exception {
  3. if (Build.VERSION.SDK_INT >= Build.VERSION_CODE.LOLLIPOP) {
  4. try {
  5. Os.chmod(path,mode);
  6. } catch (Exception e) {
  7. // ignore
  8. }
  9. }
  10.  
  11. File file = new File(path);
  12. String cmd = "chmod ";
  13. if (file.isDirectory()){
  14. cmd += " -R ";
  15. }
  16.  
  17. // %o:整数类型(八进制)
  18. String cmode = String.format("%o", mode);
  19. Runtime.getRuntime().exec(cmd + cmode + " " + path).waitFor();
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement