Results 1 to 2 of 2
  1. #1
    peuplier is offline Member
    Join Date
    Jul 2009
    Rep Power

    Default Validate a Zip file with java

    Iam looking for how to validate a zip file in java, I tried for that, to use / j2se / 1.4.2 / docs / ap i/ java / util / zip / CheckedInputStream.html , and in the definition of this class, it is said in the documentation :
    An input stream that also maintains a checksum of the data being read. The checksum can then be used to verify the integrity of the input data.
    I tried this code

    Java Code:
    public class Checksumoffile 
    public static void Checkyourfiles(String strfilename)
    	long checksum=0;
    	try {
            // Compute Adler-32 checksum
            CheckedInputStream cis = new CheckedInputStream(
                new FileInputStream(strfilename), new Adler32());
            byte[] tempBuf = new byte[128];
            while ( >= 0) {
            checksum = cis.getChecksum().getValue();
        } catch (IOException e) {
        System.out.println("The checksum of file is : " + checksum);
    Called by this code
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Checksumoffile.Checkyourfiles(TestStringTokenizing .strchemin2+"/");
    catch(Exception exop)
    System.out.println("Problem using your zip "+ exop.getMessage());

    I obtained a checksum = 0 in all cases, even when I have tried with a validate file, and a corrupt file.
    I think there is a problem for me, either my code is wrong, or I did not understand what checksum and Integrity mean. Do Checksum and Integrity mean the same think ? Are they different ?
    I use the almanac java developers 'example availlable here = exampledepot. com / egs / / ChecksumFile.html
    Thx for any help.

    PS: Despite the fact that I posted two links for the first post, I am not a spammer, Iam a java developper, if I put these two links, this is for a purpose to illustrate, and documented my message. I used to post in several java forum as developpez. com, and forum, Glassfish topic
    Last edited by peuplier; 07-10-2009 at 10:21 AM.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    seems to work unless file is not found. then checksum = 0.

    what's this?
    Checksumoffile.Checkyourfiles(TestStringTokenizing .strchemin2+"/");
    Get NotePad++ (free)

Similar Threads

  1. Replies: 7
    Last Post: 05-23-2008, 03:46 AM
  2. How to validate date using SampleDateFormat
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-04-2008, 02:38 PM
  3. repaint validate doLayout
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 1
    Last Post: 10-27-2007, 06:53 PM
  4. Replies: 3
    Last Post: 08-01-2007, 05:15 PM
  5. validate hex character
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts