我想用java比较两个edifact文件,找出它们之间的区别。请建议代码。附件是Edifact的示例文件..
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'发布于 2018-02-24 03:42:16
这实在是太痛苦了,无法尝试和吸收。我建议使用图书馆。谷歌是你的朋友。This one is literally Google code
但多年的经验也告诉我,你并没有解决最终的问题。一旦你得到你的文本比较工作,你会崩溃的事实,它是大小写敏感。一旦您了解了这一点,您就会意识到EDI属性不是特定于订单的。解决这个问题,然后你才会知道客户不仅想知道这些文档是否等价,而且如果不是,在EDI术语中,它们有什么不同之处。
我强烈建议你删除这篇文章,走一个完全不同的方向。有许多开放源代码的EDI解析器可用。通过它们运行Edifact文档。然后支持两种模式:等价性摘要;以及使它们不同的详细报告。
您现在所做的,如果只是执行MD5校验和来判断文件是否相同,将会容易得多。
发布于 2018-02-21 13:49:04
以下是我正在做的事情,但它实际上并没有给我一个正确的模式:
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");}
}
}https://stackoverflow.com/questions/48897656
复制相似问题