get Current Cpu frequency - Android Hardware

Android examples for Hardware:CPU Frequency

Description

get Current Cpu frequency

Demo Code


//package com.java2s;

import java.io.BufferedReader;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String getCurCpuFreq(int cpuNo) {
        String result = "N/A";
        String path = "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq";
        BufferedReader br = null;
        try {//w  w w.  jav a  2 s  . c  om
            FileReader fr = new FileReader(String.format(path, cpuNo));
            br = new BufferedReader(fr);
            String text = br.readLine();
            result = text.trim();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}

Related Tutorials