This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Zip getCompressSize more efficient method ? Please ?

Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I've got this method to determine the file size if I compress the file, I'm just wondering is there a better way ?
Also note that out.closeEntry(); must be called before you can obtain the size using getCompressSize() otherwise you get -1 ?
public static long getCompressSize(String file)
long compsize = 0;
byte[] buf = new byte[1024];
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(""));
FileInputStream in = new FileInputStream(file);
ZipEntry ze = new ZipEntry("dummy");
int len;
while ((len = > 0)
out.write(buf, 0, len);

// need to close the entry before
// you can obtain details
compsize = ze.getCompressedSize();
catch (FileNotFoundException e){}
catch (IOException e){}
return compsize;

[ August 20, 2002: Message edited by: Mark Nicholas ]
grapes are vegan food pellets. Eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic