code: private void readProcStatFile() {
      // Read "/proc/stat" file
      BufferedReader in = null;
      FileReader fReader = null;
      try {
        fReader = new FileReader(procfsStatFile);
        in = new BufferedReader(fReader);
      } catch (FileNotFoundException f) {
        // shouldn't happen....
        return;
      }
  
      Matcher mat = null;
      try {
        String str = in.readLine();
        while (str != null) {
          mat = CPU_TIME_FORMAT.matcher(str);
          if (mat.find()) {
            long uTime = Long.parseLong(mat.group(1));
            long nTime = Long.parseLong(mat.group(2));
            long sTime = Long.parseLong(mat.group(3));
            cumulativeCpuTime = uTime + nTime + sTime; // milliseconds
            break;
          }
          str = in.readLine();
        }
        cumulativeCpuTime *= jiffyLengthInMillis;
      } catch (IOException io) {
        LOG.warn("Error reading the stream " + io);
      } finally {
        // Close the streams
        try {
          fReader.close();
          try {
            in.close();
          } catch (IOException i) {
            LOG.warn("Error closing the stream " + in);
          }
        } catch (IOException i) {
          LOG.warn("Error closing the stream " + fReader);
        }
      }
    }
docs: Read /proc/stat file, parse and calculate cumulative CPU