Zip a folder programatically ??
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bikash_paul
Posted On:   Monday, April 21, 2003 10:30 PM

Hi all friends,



I want to zip a folder not file by using java.util.zip package. My requirement is I have one swing interface(it is basically a uploading software)on button action event i want to zip a folder by opening Filedialog Box by selecting that folder from my hard disk.Is it possible? If it is not possible then Is there any other way to zip a folder programatically not manually.Actully I want to zip a no. of files in a single folder.So that when user unzip that zip file they can find those files in a single folder.

Regards

Bikash

Hai paul,i have give programe just go throw that,it works.

Posted By:   ethiraj_krishnan  
Posted On:   Thursday, April 24, 2003 11:26 PM

You have to change instead of XML==>directory u have to give u r directory

public String[] listFiles()
{
File f=new File("XML"); // give ur directory path
String files[]=f.list();
return files;
}
public void createZipFile(String refdatabaseid)
{
String[] filenames = listFiles();
byte[] buf = new byte[1024];

try
{
String outFilename = "XML/"+refdatabaseid+".zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
System.out.println("From Create Zip:"+filenames.length);

for (int i=0; i {
FileInputStream in = new FileInputStream("XML/"+filenames[i]);
out.putNextEntry(new ZipEntry(filenames[i]));
int len;

while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
About | Sitemap | Contact