get Linux Version - Android Android OS

Android examples for Android OS:OS Version

Description

get Linux Version

Demo Code


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

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String getLinuxVersion() {
        try {//from  w ww .j a va 2  s .  c  o m
            Process process = Runtime.getRuntime()
                    .exec("cat /proc/version");
            InputStream outs = process.getInputStream();
            InputStreamReader isrout = new InputStreamReader(outs);
            BufferedReader brout = new BufferedReader(isrout, 8 * 1024);
            String result = "";
            String line;
            while ((line = brout.readLine()) != null) {
                result += line;
            }
            if (result != "") {
                String keyWord = "version ";
                int index = result.indexOf(keyWord);
                line = result.substring(index + keyWord.length());
                index = line.indexOf(" ");
                return line.substring(0, index);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials