读取大文件

import java.io.*;
import java.util.*;
public class ReadBigFile
{
  public static void main(String args[]) throws Exception
  {
   long oldTime = System.currentTimeMillis();
   File file = new File("e:\\bigFile.txt");     
   BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));      
   BufferedReader reader = new BufferedReader(new InputStreamReader(fis));  
       
   String lineStr = ""; 
   int n = 0;
   while((lineStr = reader.readLine()) != null){  
    boolean b = findNum(lineStr);
    if(b) n++;
   }
   long newTime = System.currentTimeMillis();
   long seconds = (newTime - oldTime)/1000;
   System.out.println(n);
   System.out.println("耗时:"+seconds);
   
  }
  public static boolean findNum(String str)
  { 
   boolean output = false;
   if(-1 != str.indexOf("age=10"))
   {    
    output = true;
   }
   return output;
  }
}

你可能感兴趣的:(Java技术)