Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Creation of .zip file???

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam new to this package.I want to compress one file(for example test.doc)for that I want to make .zip file of that .doc file.Iam selecting file through opening FileDialog on the actionevent of button and now I want to compress that file in .zip format at maximum level of compression "9".Can any one plz give me some code for that.For this help I shall ever gratfull to u.
Thanks in Advance
Bikash :roll:
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you check out the classes in java.util.zip, or is that what you're asking about?
--Mark
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Ya, Iam asking about java.util.zip package but Iam confused how I can set the compression level.Can plz give me some code for that.
Regards
Bikash
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I've never used it, but the class java.util.zip.Deflater looks like what you want. Just create a Deflator, set the level in the call to the consturctor, put the bytes into it, then get the bytes out.
--Mark
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Below r my codes can u tell where I should add Deflater class with specified level I know we can set the level from 0-9 for best compression I want to use level "9".Can u plz help me.Iam trying this coz i want to compress my files during uploading.
import java.io.*;
import java.util.zip.*;
public class zipper1 {
public static final void main(String [] args){
try {
File myDir=File("c:\\html");
ZipOutputStream outStream = new ZipOutputStream (new FileOutputStream("c:\\html\\out.zip"));
outStream.setMethod(ZipOutputStream.DEFLATED);
processFile(myDir, "SPLASH.gif",outStream);
outStream.close();
}
catch(Exception e){
e.printStackTrace();
}
}
static void processFile(File myDir, String fileName, ZipOutputStream out)
{
try
{
File f = new File(myDir, fileName);
FileInputStream in = new FileInputStream(f);
// Add ZIP entry to output stream.
ZipEntry e1 = new ZipEntry(fileName);
out.putNextEntry(e1);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
catch (Exception e)
{
System.out.println("Error ::" + e);
}

}
}
Regards
Bikash
:roll:
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic