Reputation: 1
I want to compare two edifact files and find the differences between them as well using java. Please suggest the code. Sample file of Edifact is attached..
UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778'
UNH+00000000000117+INVOIC:D:97B:UN'
BGM+380+342459+9'
DTM+3:20060515:102'
RFF+ON:521052'
NAD+BY+792820524::16++CUMMINS MID-RANGE ENGINE PLANT'
NAD+SE+005435656::16++GENERAL WIDGET COMPANY'
CUX+1:USD'
LIN+1++157870:IN'
IMD+F++:::WIDGET'
QTY+47:1020:EA'
ALI+US'
MOA+203:1202.58'
PRI+INV:1.179'
LIN+2++157871:IN'
IMD+F++:::DIFFERENT WIDGET'
QTY+47:20:EA'
ALI+JP'
MOA+203:410'
PRI+INV:20.5'
UNS+S'
MOA+39:2137.58'
ALC+C+ABG'
MOA+8:525'
UNT+23+00000000000117'
UNZ+1+00000000000778'
Upvotes: 0
Views: 804
Reputation: 927
This is just too painful to try and absorb. I suggest using a library. Google is your friend. This one is literally Google code
BUT many years of experience also tells me that you are not solving the END problem. As soon as you get your Text Compare working you're going crash into the fact it's case sensitive. Once you get past that you're going to realize the EDI attributes are not order specific. Fix that and only then will you learn the customer wants to know not only if the documents are equivalent but if not what is different about them IN EDI TERMS.
I STRONGLY recommend you delete this and go a completely different direction. There are numerous open source EDI parsers available. Run the Edifact documents through them. Then support two modes: A Summary of equivalence; AND a detailed report of WHAT makes them different.
What you're doing now would be far easier to just do an MD5 checksum to say if the files are identical or not.
Upvotes: 1
Reputation: 1
Here is what I am working on but it is not actually giving me result in a proper pattern:
import java.io.*;
import java.util.*;
public class Compare_EDIFiles
{
public static void main (String[] args) throws java.io.IOException
{
//Getting the name of the files to be compared.
FileReader fis1 = new FileReader ("filename1");
FileReader fis2 = new FileReader ("filename2);
String s1="";
String s2="",s3="",s4="";
String y="",z="";
//Reading the contents of the files
BufferedReader br = new BufferedReader (fis1);
BufferedReader br1 = new BufferedReader (fis2);
while((z=br1.readLine())!=null)
s3+=z;
while((y=br.readLine())!=null)
s1+=y;
System.out.println ();
//String tokenizing
int numTokens = 0;
//String delim = ":";
//String delim1 = ":";
StringTokenizer st = new StringTokenizer (s1);
String[] a = new String[10000];
for(int l=0;l<10000;l++)
{
a[l]="";
}
int i=0;
while (st.hasMoreTokens())
{
s2 = st.nextToken();
a[i]=s2;
i++;
numTokens++;
}
int numTokens1 = 0;
StringTokenizer st1 = new StringTokenizer (s3);
String[] b = new String[10000];
for(int k=0;k<10000;k++)
{
b[k]="";
}
int j=0;
while (st1.hasMoreTokens())
{
s4 = st1.nextToken();
b[j]=s4;
j++;
numTokens1++;
}
//comparing the contents of the files and printing the differences, if any.
int x=0;
for(int m=0;m<a.length;m++)
{
if(a[m].equals(b[m])){}
else
{
x++;
System.out.println(a[m] + " -- " +b[m]);
System.out.println();}
}
System.out.println("No. of differences : " + x);
if(x>0){System.out.println("Files are not equal");}
else{System.out.println("Files are equal. No difference found");}
}
}
Upvotes: 0