Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
    }
}