이미지 비교 (image comparision)
public class ImageCompare {
private String originPath;
private String cdnPath;
private boolean same = true;
int b1 = 0, b2 = 0, pos = 1;
public ImageCompare(String originPath, String cdnPath) {
this.originPath = originPath;
this.cdnPath = cdnPath;
}
public boolean compare() throws IOException {
try (
BufferedInputStream compare1 = new BufferedInputStream(new URL(originPath).openStream());
BufferedInputStream compare2 = new BufferedInputStream(new URL(cdnPath).openStream());
) {
while (b1 != -1 && b2 != -1) {
if (b1 != b2) {
log.info(" two file was different. : {}, {}", originPath, cdnPath);
same = false;
break;
}
pos++;
b1 = compare1.read();
b2 = compare2.read();
}
}
return same;
}
}
참고 : https://dzone.com/articles/comparing-files-in-java
Comparing Files in Java - DZone Java
This lesson in Java NIO and memory mapping involves creating a simple Java application to compare files while safeguarding performance.
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.