Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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