Java tutorial
//package com.java2s; import java.io.DataOutputStream; import java.io.IOException; public class Main { public static boolean isRoot() { Process process = null; DataOutputStream dos = null; try { process = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(process.getOutputStream()); dos.writeBytes("exit\n"); dos.flush(); int exitValue = process.waitFor(); if (exitValue == 0) { return true; } } catch (IOException e) { } catch (InterruptedException e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { } } } return false; } }