Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:44:56+00:00 2026-05-31T22:44:56+00:00

How can I read and write comments in a Zip file, using Java? I

  • 0

How can I read and write comments in a Zip file, using Java?

I can write comments with this:

FileOutputStream fos = new FileOutputStream(output);
ZipOutputStream zos = new ZipOutputStream(fos);
zos.setComment("BMC Comment");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:44:57+00:00Added an answer on May 31, 2026 at 10:44 pm

    Check this post:

    • http://www.flattermann.net/2009/01/read-a-zip-file-comment-with-java/

    Edit: unfortunately the original link is now unavailable, here’s a Web archive link:

    http://web.archive.org/web/20100117212418/http://www.flattermann.net:80/2009/01/read-a-zip-file-comment-with-java/

    For posterity, here’s the gist (slightly formatted):

    private static String getZipCommentFromBuffer (byte[] buffer, int len) {
      byte[] magicDirEnd = {0x50, 0x4b, 0x05, 0x06};
      int buffLen = Math.min(buffer.length, len);
    
      // Check the buffer from the end
      for (int i = buffLen - magicDirEnd.length - 22; i >= 0; i--) {
        boolean isMagicStart = true;
    
        for (int k = 0; k < magicDirEnd.length; k++) {
          if (buffer[i + k] != magicDirEnd[k]) {
            isMagicStart = false;
            break;
          }
        }
    
        if (isMagicStart) {
          // Magic Start found!
          int commentLen = buffer[i + 20] + buffer[i + 21] * 256;
          int realLen = buffLen - i - 22;
          System.out.println ("ZIP comment found at buffer position " 
            + (i + 22) + " with len = " + commentLen + ", good!");
    
          if (commentLen != realLen) {
            System.out.println ("WARNING! ZIP comment size mismatch: "
              + "directory says len is " + commentLen
              + ", but file ends after " + realLen + " bytes!");
          }
    
          String comment = new String (buffer, i + 22, Math.min(commentLen, realLen));
          return comment;
        }
      }
    
      System.out.println ("ERROR! ZIP comment NOT found!");
      return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I read/write serializable object instances to a RandomAccessFile in Java? I want
How can i check the read/ write permission of the file storing media? ie
I want to write a file where an external application can read it, but
Is there any class in the .NET framework that can read/write standard .ini files:
I created a SQLite database on Android device. The program can read/write to database
I'm looking for an editor that can read and write remote PHP files via
Is there a stand-alone GUI designer that can read and write the .form files
With D and Tango library can I read and write in the ANSI encoding
Can anoyne recommend a good library that will let me easily read/write private member
I need to read out posts and maybe write back comments to a WordPress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.