Hi,

I'm reading a file and doing some operations on it..It is a huge file

going in GB's.....

The code is working correctly but is very slow....How do i optimise

it...

My code snipnet is:

class Risk

{

public void compare(String infile) throws IOException

{

cnt=0;

for(i=0;i<qid.size();i++)

{

no=0;

fr=new FileReader(infile);

br=new BufferedReader(fr);

while((str=br.readLine())!=null)

{

no++;

if((str.startsWith("$"))||(str.startsWith("-CONT-")))

continue;

else

{

s2=str.substring(0,10);

if(s2.equals(qid.elementAt(i)))

{

cnt++;

start=no;

end=no+29;

quadarray(infile,start,end);

}

if((cnt==sc) && (i<qid.size()))

{

System.out.println("qid="+qid.elementAt(i));

cnt=0;

writesubcase1();

}

}

}

fr.close();

}

for(i=0;i<tid.size();i++)

{

no=0;

fr=new FileReader(infile);

br=new BufferedReader(fr);

while((str=br.readLine())!=null)

{

no++;

if((str.startsWith("$"))||(str.startsWith("-CONT-")))

continue;

else

{

s2=str.substring(0,10);

if(s2.equals(tid.elementAt(i)))

{

cnt++;

start=no;

end=no+29;

triaarray(infile,start,end);

}

if((cnt==sc) && (i<tid.size()))

{

System.out.println("tid="+tid.elementAt(i));

cnt=0;

writesubcase2();

}

}

}

fr.close();

}

}

public void quadarray(String ifile,int start,int end) throws

IOException

{

try

{

fr1=new FileReader(ifile);

br1=new BufferedReader(fr1);

line=0;

k=0;

x=0;

while((str1=br1.readLine())!=null)

{

line++;

if((line>=start) && (line<end))

{

if(j==0)

quad[j][k]=str1;

if((k==3) ||(k==17)||(k==20))

{

val1=Double.parseDouble(str1.substring(18,36));

if(val1>qmax[x])

{

qmax[x]=val1;

x++;

}

}

if((k==5) ||(k==

||(k==22)||(k==25))

{

val2=Double.parseDouble(str1.substring(54,72));

if(val2>qmax[x])

{

qmax[x]=val2;

x++;

}

}

if((k==11)||(k==14)||(k==2

)

{

val3=Double.parseDouble(str1.substring(36,54));

if(val3>qmax[x])

{

qmax[x]=val3;

x++;

}

}

k++;

}

}

}

catch (Exception e)

{ }

}

public void writesubcase1() throws IOException

{

x=0;

try

{

fw=new FileWriter("Result.txt",true);

for(y=0;y<30;y++)

{

if((y==0)||(y==1)||(y==2)||(y==4)||(y==6)||(y==7)| |(y==9)||

(y==10)||(y==12)||(y==13)||(y==15) || (y==16)||(y==1

||(y==19)||

(y==21)||(y==23)||(y==24) || (y==26)||(y==27))

{

fw.write(quad[0][y]+"\n");

continue;

}

else

{

if((y==3)||(y==17)||(y==20))

{

s=quad[0][y];

fw.write(s.substring(0,2

+qmax[x]+s.substring(37)+"\n");

x++;

continue;

}

if((y==5)||(y==

||(y==22)||(y==25))

{

s=quad[0][y];

fw.write(s.substring(0,64)+qmax[x]+"\n");

x++;

continue;

}

if((y==11)||(y==14))

{

s=quad[0][y];

fw.write(s.substring(0,46)+qmax[x]+s.substring(55)+"\n");

x++;

continue;

}

if(y==2

{

s=quad[0][y];

fw.write(s.substring(0,46)+qmax[x]+"\n");

x++;

break;

}

}

}

fw.close();

}

catch(Exception e)

{}

}

public void triaarray(String ifile,int start,int end) throws

IOException

{

try

{

fr1=new FileReader(ifile);

br1=new BufferedReader(fr1);

line=0;

while((str1=br1.readLine())!=null)

{

line++;

if((line>=start) && (line<end))

{

if(j==0)

tria[j][k]=str1;

if(k==2)

{

val1=Double.parseDouble(str1.substring(37,54));

if(val1>tmax[0])

tmax[0]=val1;

}

if(k==5)

{

val2=Double.parseDouble(str1.substring(19,36));

if(val2>tmax[1])

tmax[1]=val2;

}

k++;

}

}

}

catch(Exception e)

{}

}

public void writesubcase2()

{

try

{

fw=new FileWriter("Result.txt",true);

for(y=0;y<7;y++)

{

if((y==0)||(y==1)||(y==3)||(y==4))

{

fw.write(tria[0][y]+"\n");

continue;

}

if(y==2)

{

s=tria[0][y];

fw.write(s.substring(0,47)+tmax[0]+s.substring(55)+"\n");

continue;

}

if(y==5)

{

s=tria[0][y];

fw.write(s.substring(0,29)+tmax[1]+"\n");

break;

}

}

fw.close();

}

catch(Exception e)

{}

}

public static void main(String args[])

{

Risk r=new Risk();

ipfile=args[0];

try

{

r.compare(ipfile);

}

catch (Exception e)

{ }

}

}

The code takes a lot of time in functions Quadarray and Triaaray.

As u can see the de is very simple in these functions but still it

takes lot of time...

How do i improve it??