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
package comm;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;*emphasized text*
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Zip1 {
public static void main( String[] args )
{
byte[] buffer = new byte[1024];
try{
File f= new File("E:\\");
f.mkdirs();
File origFile= new File(f,"MyZipFile2.zip");
FileOutputStream fos = new FileOutputStream(origFile);
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze= new ZipEntry("test.pdf");
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream("D:\\Test.pdf");
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
zos.closeEntry();
//remember close it
zos.close();
System.out.println("Done");
}catch(IOException ex){
ex.printStackTrace();
}
}
}