chown, change owner via shell command - Android Android OS

Android examples for Android OS:Shell Command

Description

chown, change owner via shell command

Demo Code


import java.io.File;
import java.io.IOException;
import android.util.Log;

public class Main{
    public static int chown(File f, String uid) {
        String cmd = "chown " + uid + " " + f.getAbsolutePath();
        Log.i(Mocker.TAG, "Running command: " + cmd);
        return exec(cmd);
    }/*from  ww w  . j a  va2s .  c o  m*/
    private static int exec(String cmd) {
        try {
            Runtime runtime = Runtime.getRuntime();
            Process p = runtime.exec(cmd);
            return p.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        } catch (InterruptedException e) {
            e.printStackTrace();
            return -1;
        }
    }
}

Related Tutorials