Here you can find the source of runAsRoot(String[] commands)
public static void runAsRoot(String[] commands) throws IOException, InterruptedException
//package com.java2s; import java.io.DataOutputStream; import java.io.IOException; public class Main { public static void runAsRoot(String[] commands) throws IOException, InterruptedException { Process p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); for (String cmd : commands) { os.writeBytes(cmd + "\n"); }//from www. jav a 2s .co m os.writeBytes("exit\n"); os.flush(); os.close(); p.waitFor(); } }