This discussion is archived
5 Replies Latest reply: Apr 16, 2007 4:57 AM by 807606 RSS

Getting ioexception with the posted  program with randomaccessfile

807606 Newbie
Currently Being Moderated
SEARCH_1.java<<<<<<<<<<<<<<<<<<<<<<<<<
import java.io.*;
import java.util.*;
import java.io.*;
public class Search_1 {
     RandomAccessFile source,destination;

String matcher="[cluster-30GB-rep-1]";
//String matcher="name";
     String buffer;

     public Search_1()
     {

try{
source=new RandomAccessFile("log.txt","rw");
destination=new RandomAccessFile("New.txt","rw");
     process();     

     }
     catch(Exception e) {
     System.out.println("Sdf");
     }
     
}
public void process() throws IOException
{
     
          while(source.readLine()!=null)
{     

     buffer=source.readLine();     

          StringTokenizer tokens= new StringTokenizer(buffer);
          while(tokens.hasMoreTokens())
          
     { 

     if(matcher.equals(tokens.nextElement()))
          {
          destination.writeBytes(buffer +"\n");
          }

     }
     
     
}
}
}



SEARCHTEST.java<<<<<<<<<<<<<<<<<
import java.io.IOException;
public class SearchTest
{
public static void main( String args[] )
{
Search_1 application=new Search_1();
}}






what i m trying with that program is if a particular keyword(job id no.) is present in log.txt file string,then that whole string is needed in other file namely new.txt
i m using randomaccessfile becoz the log.txt is going to be a big file..