Code example for RandomAccessFile

Methods: close, readLine, seek, sleep

0
 
	private float readUsage() 
	{ 
		try 
		{ 
			RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
			String load = reader.readLine();
 
			String[] toks = load.split(" ");
 
			long idle1 = Long.parseLong(toks[5]);
			long cpu1 = Long.parseLong(toks[2]) + Long.parseLong(toks[3])
					+ Long.parseLong(toks[4]) + Long.parseLong(toks[6])
					+ Long.parseLong(toks[7]) + Long.parseLong(toks[8]);
 
			try 
			{ 
				Thread.sleep(360);
			} 
			catch (Exception e)
			{ 
			} 
 
			reader.seek(0);
			load = reader.readLine();
			reader.close();
 
			toks = load.split(" ");
 
			long idle2 = Long.parseLong(toks[5]);
			long cpu2 = Long.parseLong(toks[2]) + Long.parseLong(toks[3])