I have one file created by 7zip program. I used deflate method to compress it. Now I want to create the same archive (with the same MD5sum) in java
To generate two identical zip files (including identical md5sum) from the same source file, I would recommend using the same zip utility -- either always use the same Java program, or always use 7zip.
The 7zip utility for instance has a lot of options -- many of which are simply defaults that can be customized (or differ between releases?) -- and any Java zip implementation would have to also set these options explicitly. If your Java app can simply invoke an external "7z" program, you'll probably get better performance anyway that a custom Java zip implementation. (This is also a good example of a map-reduce problem where you can easily scale out the implementation.)
But the main issue you will run into if you have a server-side generated zip file and a client-side generated zip file is that the zip file stores two things in addition to just the original file: (1) the file name, and (2) the file timestamp. If either of these have changed, then the resulting zip file will have a different md5sum:
$ ls tst1/
foo.tar
$ cp -r tst1 tst2
$ ( cd tst1; zip foo.zip foo.tar ) ; ( cd tst2; zip foo.zip foo.tar ) ; md5sum tst?/foo.zip
updating: foo.tar (deflated 20%)
updating: foo.tar (deflated 20%)
359b82678a2e17c1ddbc795ceeae7b60 tst1/foo.zip
b55c33c0414ff987597d3ef9ad8d1d08 tst2/foo.zip
But, using "cp -p" (preserve timestamp):
$ cp -p -r tst1 tst2
$ ( cd tst1; zip foo.zip foo.tar ) ; ( cd tst2; zip foo.zip foo.tar ) ; md5sum tst?/foo.zip
updating: foo.tar (deflated 20%)
updating: foo.tar (deflated 20%)
359b82678a2e17c1ddbc795ceeae7b60 tst1/foo.zip
359b82678a2e17c1ddbc795ceeae7b60 tst2/foo.zip
You'll find the same problem with differing filenames and paths, even when the files inside the zip are identical.