Using chmod in Android

Java doesn't have native support for platform dependent operations like chmod. However, Android provides utilities for some of these operations via android.os.FileUtils. The FileUtils class is not part of the public SDK and is therefore not supported. So, use this at your own risk:
public int chmod(File path, int mode) throws Exception {
  Class fileUtils = Class.forName("android.os.FileUtils");
  Method setPermissions =
      fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
  return (Integer) setPermissions.invoke(null, path.getAbsolutePath(), mode, -1, -1);

chmod("/foo/bar/baz", 0755);


  1. This is great solution Damon. Thanks a lot for pointing it to me. I have problems running external 'chmod' shell command from Java code in my tablet, but this works perfectly.

  2. Thanks a lot man !! Very usefull :)

  3. This is not working code, I try to change permission of data/system/password.key file and this code doesn't help me.

    1. It worked at some point... This post is rather old. For others that visit this page, could you specify your Android version and device?

  4. Hi Damon Kohler ,

    I m working on screenshot app , which need to start a native service to take a screenshot of any activity.

    So i need to start a service by my app ..

    How to modify the below code to work in android,,,,,

    adb.exe push ./asl-native /data/local/asl-native
    adb.exe shell /system/bin/chmod 0777 /data/local/asl-native

    adb.exe shell kill -9 "/data/local/asl-native"
    adb.exe shell "/data/local/asl-native /data/local/asl-native.log"

    Thanking You

  5. Android version 2.3.7 doesn't work.

  6. I'm glad to see this post. By the way, you may be interested in replica ray bans.