Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    private static final String TAG = "CpuUtils";

    public static long getMaxCpuFreq() {
        long longRet = 0;
        String result = "0";
        ProcessBuilder cmd;
        try {
            String[] args = { "/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };
            cmd = new ProcessBuilder(args);
            Process process = cmd.start();
            InputStream in = process.getInputStream();
            byte[] re = new byte[24];
            result = "";
            while (in.read(re) != -1) {
                result = result + new String(re);
            }
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            result = "0";
        }

        if (result.length() != 0) {
            try {
                longRet = Long.valueOf(result.trim());
            } catch (Exception e) {
                android.util.Log.e(TAG, "");
            }
        }
        return longRet;
    }
}