import java.io.*; import java.io.IOException; import java.util.zip.*; import java.util.zip.CheckedOutputStream; import java.util.zip.CheckedInputStream; public class CheckedDemo { static long readCis, writeCis; public static void main(String args[]) { String newfile = "newtestfile.txt"; String oldfile = "oldtestfile1.txt"; byte[] buffer = new byte[1024]; try { FileOutputStream fout = new FileOutputStream(newfile); CheckedOutputStream outputtream = new CheckedOutputStream(fout, new CRC32()); FileInputStream inStream = new FileInputStream(oldfile); int length; while ((length = inStream.read(buffer)) > 0) { outputtream.write(buffer, 0, length); } inStream.close(); long writeCis = outputtream.getChecksum().getValue(); System.out.println("The value of Checksum is at writing time : " + writeCis); } catch (IOException ex) { System.out.println("Exception : " + ex.getMessage()); } try { FileInputStream fin = new FileInputStream(newfile); CheckedInputStream inputStream = new CheckedInputStream(fin, new CRC32()); byte[] buffer2 = new byte[100]; while (inputStream.read(buffer2) >= 0) { long readCis = inputStream.getChecksum().getValue(); System.out .println("value of checksum Affter reading new file : " + readCis); } } catch (IOException e) { System.out.println("the exception has been thrown" + e); System.exit(1); } if (writeCis == readCis) { System.out.println("No error in new file data"); } else { System.out.println(" error in new file data"); } } }