Results 1 to 7 of 7

Thread: Is Zip or not?

  1. #1
    icsbcn is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default Is Zip or not?

    Hello

    I wonder how I know if a particular file is a zip or not.
    Anyone have any ideas?

    I tried to do this:

    Java Code:
     FileInputStream fis = new FileInputStream(argv[0]);  
                ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));  
    ZipEntry entry;  
    while((entry = zis.getNextEntry()) != null) {  
       
     MYCODE  
       
     }
    The problem is that I can not distinguish between a non-zip file and a empty zip file...

    Thank you very much.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi,
    Please repeat ur question clearly.

    U can check whether the file ends with zip or not know for finding out whethether it is a zip file?.
    Ramya:cool:

  3. #3
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Or check the first two bytes of the file equal PK
    My Hobby Project: LegacyClone

  4. #4
    icsbcn is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by mrmatt1111 View Post
    Or check the first two bytes of the file equal PK
    Hi,

    I am interested in your argument. Could you explain more specifically what you mean?

    Thank you so much.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by icsbcn View Post
    Hello
    The problem is that I can not distinguish between a non-zip file and a empty zip file...
    How is that a problem? Either you can parse it, or you can't, same difference, so why, exactly, do you need to know whether it was an actual zipfile or not?

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Hi,
    Please repeat ur question clearly.

    U can check whether the file ends with zip or not know for finding out whethether it is a zip file?.
    So rename a text file so it has a .zip ending and this is now a zipfile? Windoof thinks so, but I didn't think anyone else really believed that.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by icsbcn View Post
    Hi,

    I am interested in your argument. Could you explain more specifically what you mean?

    Thank you so much.
    Read the first two bytes of the file using FileInputStream and it's read methods (a FileInputStream, not a FileReader), then close that inputstream before initiating the Zip classes.

Tags for this Thread

Posting Permissions

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