Reputation: 959
Can anyone provide a sample code to zip a file in codename one with zipme? I checked the sample on zipme webpage but only have the unzip sample code. zipme project Thank you.
Upvotes: 1
Views: 40
Reputation: 959
I have done a procedure to zip a file. But I can't unzip the zip file by 7-zip.
public static void zipFile(String zipFile, String srcFile) throws IOException {
InputStream i = FileSystemStorage.getInstance().openInputStream(srcFile);
OutputStream o = FileSystemStorage.getInstance().openOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(o);
zos.putNextEntry(new ZipEntry(srcFile));
int len;
byte[] buffer = new byte[1024];
while ((len = i.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
zos.closeEntry();
}
Upvotes: 0
Reputation: 52770
I didn't try this but I guess it would look pretty close to this:
try(ZipOutputStream output = new ZipOutputStream(destinationOutputStream)) {
output.putNextEntry(new ZipEntry("NameOfFileInZip"));
output.write(byteArrayContentOfFileInZip);
}
Check out ZipOutputStream
samples for further guidance. Should be pretty similar to standard JavaSE only with different packages and more limited API.
Upvotes: 1