I have a text file as follows
I have to retrieve only those values which fall in the mem, swap and total under total, used and free i.e. I have to ignore 0, 564, 3237, 4074, 3848. How do I do it?Code:total used free shared buffers cached Mem: 7923 7875 47 0 564 3237 -/+ buffers/cache: 4074 3848 Swap: 12287 1067 11220 Total: 20211 8943 11267
I have written the following code to display the all the numbers.
Code:package my.scan; import java.util.*; //importing some java classes import java.lang.*; import java.io.*; class ReadFile { void getFile () { int i = 0; try { Scanner myFile = new Scanner(new FileReader("C:/Documents and Settings/shikhau/workspace/SanNumber/freelast.txt")); while (myFile.hasNext()) { if (myFile.hasNextInt()) { i = myFile.nextInt(); System.out.println(i); } else { myFile.next(); } } } catch (FileNotFoundException e){ System.out.println("Sorry! This file is not found"); } } } public class ScanNum { public static void main(String[] args) { ReadFile rf = new ReadFile(); rf.getFile(); } }


Reply With Quote
Bookmarks