Java examples for Native OS:Shell Command
root Cmd
//package com.java2s; import java.io.DataOutputStream; import java.io.IOException; public class Main { public static void main(String[] argv) throws Exception { String cmd = "java2s.com"; System.out.println(rootCmd(cmd)); }//from w w w . ja v a2s . c o m public static Process rootCmd(String cmd) { Process p = null; try { p = Runtime.getRuntime().exec("/system/xbin/su"); DataOutputStream ou = new DataOutputStream(p.getOutputStream()); try { String str1 = String.valueOf(cmd); String str2 = str1 + "\n"; ou.writeBytes(str2); ou.flush(); } catch (Exception e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } return p; } }