我正在生成一个ODS电子表格作为Java程序的输出。我目前正在尝试设置相同的测试用例。为此,我需要将预期输出和实际输出进行比较。我目前正在使用ODFToolkit创建文档。
如何比较Java程序中的两个电子表格(预期的和实际的)?
发布于 2012-02-27 16:25:23
如果有人需要解决方案,这里就有。
public static boolean contentsAreIdentical(OdfSpreadsheetDocument document1, OdfSpreadsheetDocument document2) {
try {
ByteArrayInputStream bis1 = (ByteArrayInputStream) document1.getContentStream();
ByteArrayInputStream bis2 = (ByteArrayInputStream) document2.getContentStream();
if(bis1.available() != bis2.available()) {
return false;
}
while(true){
int a = bis1.read();
int b = bis2.read();
if(a != b){
return false;
}
if(a == -1){
return true;
}
}
} catch (Exception e) {
//Do something with exception
}
return false;
} https://stackoverflow.com/questions/9351186
复制相似问题