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.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static String[] getUvTableNames() {
        ArrayList<String> Tokens = new ArrayList<String>();

        try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = null;
            File f = new File("/sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels");
            if (f.exists()) {
                fstream = new FileInputStream("/sys/devices/system/cpu/cpufreq/vdd_table/vdd_levels");
            } else {
                File ff = new File("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
                if (ff.exists()) {
                    fstream = new FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
                }
            }
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            // Read File Line By Line
            while ((strLine = br.readLine()) != null) {
                strLine = strLine.trim();

                if ((strLine.length() != 0)) {
                    String[] names = strLine.replaceAll(":", "").split("\\s+");
                    Tokens.add(names[0]);
                }

            }
            // Close the input stream
            in.close();
        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
        String[] names = new String[Tokens.size() - 1];
        names = Tokens.toArray(names);
        return names;
    }
}