Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FileFilter;
import java.util.regex.Pattern;

public class Main {

    public static int cpuNums() {
        int nums = 1;
        try {
            File file = new File("/sys/devices/system/cpu/");
            File[] files = file.listFiles(new FileFilter() {
                @Override
                public boolean accept(File arg0) {
                    if (Pattern.matches("cpu[0-9]", arg0.getName())) {
                        return true;
                    }
                    return false;
                }
            });
            nums = files.length;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return nums;
    }
}