Hi All
I use the following code to Zip a file
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream("/sdcard/tmp.zip");
ZipOutputStream out = new ZipOutputStream(new
BufferedOutputStream(dest));
byte data[] = new byte[2048];
FileInputStream fi = new FileInputStream(file);
origin = new BufferedInputStream(fi , 2048);
ZipEntry entry = new
ZipEntry(file.getName().substring(file.getName().lastIndexOf("/") + 1));
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, 2048)) != -1) {
out.write(data, 0, count);
}
out.closeEntry();
origin.close();
out.close();
However when I use this code to Unzip the file
FileInputStream fis = new FileInputStream("/sdcard/tmp.zip");
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
int size;
byte[] buffer = new byte[2048];
FileOutputStream fos = new FileOutputStream(entry.getName());
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
It crashes on the entry = zis.getNextEntry()
java.io.EOFException
at libcore.io.Streams.readFully(Streams.java:49)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:269)
at org.TransferActivity.SaveFile(TransferActivity.java:130)
at org.TransferActivity.RecvFiles(TransferActivity.java:204)
at org.TransferActivity.access$1(TransferActivity.java:175)
at org.TransferActivity$ClickListener.onClick(TransferActivity.java:67)
at android.view.View.performClick(View.java:3110)
at android.view.View$PerformClick.run(View.java:11934)
Can anyone please help with this??
Thanks in Advance
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en