get System Property via Shell - Android java.util

Android examples for java.util:Properties

Description

get System Property via Shell

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String getSystemProperty(String propName) {
        String line = "";
        BufferedReader input = null;
        try {/*  w  w  w. j  a  v a2s . c  o  m*/
            Process p = Runtime.getRuntime().exec("getprop " + propName);
            input = new BufferedReader(new InputStreamReader(
                    p.getInputStream()), 1024);
            line = input.readLine();
            input.close();
        } catch (IOException ex) {
            //Log.e(TAG, "Unable to read sysprop " + propName, ex);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    //      Log.e(TAG, "Exception while closing InputStream", e);
                }
            }
        }
        return line;
    }
}

Related Tutorials