Hi all,
Please suggest me where i'm goin goin wrng.
I have 2 flat files. one of them is the main file(Ann.dat) has a about 150,000 lines (each line has unique ID from 00001 to 45000) of data and the the other(Miss.dat) has a just a list of IDs that are no longer in use & have to be deleted from the first file(NewAnn.dat). (Note that Ann.dat is a tab delimitted file and Miss.dat is just a list of all invalid IDs)
Below is my code. It doesn't do what I'm supposed to. Please suggest me or help me with a code to do it. What I'm trying to do is read each of the lines from the 2 files compare the ID in ann.dat with all the IDs in Miss.dat & if it doesn't match with the ID in Miss.dat write the whole line to NewAnn.dat. And do the rest with all the lines in Ann.dat.
It could be a real dumb question. since i'm not a software professional, I consider myself to be newbie to programming. I desperately need your help.
import java.io.*;
import java.util.*;
public class anntemp{
public static void main(String[] args)
{
String keyAnn ="";
String keyMis="";
String recAnn =null;
String recMis =null;
try{
FileReader fr=new FileReader("C:\\Tom\\Ann.dat");
BufferedReader br=new BufferedReader(fr);
int couter=0;
while ((recAnn = br.readLine())!=null)
{
couter++;
keyAnn = recAnn.substring(0, recAnn.indexOf("\t"));
FileReader fr1=new FileReader("C:\\Tom\\Miss.dat");
BufferedReader br1=new BufferedReader(fr1);
while((recMis = br1.readLine())!=null){
keyMis = recMis.substring(0, recMis.indexOf("\t"));
if(keyAnn.equals(keyMis)){
FileWriter fw=new FileWriter("C:\\Tom\\NewAnn.dat",true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw=new PrintWriter(bw);
StringBuffer writeValue = new StringBuffer();
writeValue.append(recAnn);
pw.println(writeValue.toString());
pw.flush();
}
}
}
}catch (Exception expe){
System.out.println("In Exception ");
expe.printStackTrace();
}
}
}
Thank you all in advance,
br
Please suggest me where i'm goin goin wrng.
I have 2 flat files. one of them is the main file(Ann.dat) has a about 150,000 lines (each line has unique ID from 00001 to 45000) of data and the the other(Miss.dat) has a just a list of IDs that are no longer in use & have to be deleted from the first file(NewAnn.dat). (Note that Ann.dat is a tab delimitted file and Miss.dat is just a list of all invalid IDs)
Below is my code. It doesn't do what I'm supposed to. Please suggest me or help me with a code to do it. What I'm trying to do is read each of the lines from the 2 files compare the ID in ann.dat with all the IDs in Miss.dat & if it doesn't match with the ID in Miss.dat write the whole line to NewAnn.dat. And do the rest with all the lines in Ann.dat.
It could be a real dumb question. since i'm not a software professional, I consider myself to be newbie to programming. I desperately need your help.
import java.io.*;
import java.util.*;
public class anntemp{
public static void main(String[] args)
{
String keyAnn ="";
String keyMis="";
String recAnn =null;
String recMis =null;
try{
FileReader fr=new FileReader("C:\\Tom\\Ann.dat");
BufferedReader br=new BufferedReader(fr);
int couter=0;
while ((recAnn = br.readLine())!=null)
{
couter++;
keyAnn = recAnn.substring(0, recAnn.indexOf("\t"));
FileReader fr1=new FileReader("C:\\Tom\\Miss.dat");
BufferedReader br1=new BufferedReader(fr1);
while((recMis = br1.readLine())!=null){
keyMis = recMis.substring(0, recMis.indexOf("\t"));
if(keyAnn.equals(keyMis)){
FileWriter fw=new FileWriter("C:\\Tom\\NewAnn.dat",true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw=new PrintWriter(bw);
StringBuffer writeValue = new StringBuffer();
writeValue.append(recAnn);
pw.println(writeValue.toString());
pw.flush();
}
}
}
}catch (Exception expe){
System.out.println("In Exception ");
expe.printStackTrace();
}
}
}
Thank you all in advance,
br