dcsimg
How to zip a directory which contails some files and subdirectories
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chander_kumar
Posted On:   Wednesday, July 3, 2002 06:09 AM


I have to zip a directory which contains files and subdirectories, the subdirectory inturn may contain files and subdirectories



If you have any sample code for this ...it will be a greate help

Re: How to zip a directory which contails some files and subdirectories

Posted By:   Gautam_Marwaha  
Posted On:   Thursday, July 4, 2002 01:48 AM

here's a quick and dirty one which uses the jar utility...


import java.io.*;

public class RuntimeExecJar
{
private boolean verbose = true;
private void runExec(String c)
{
Process p = null;
try
{
p = Runtime.getRuntime().exec(c);
BufferedReader d = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = null;
while ((s = d.readLine()) != null)
debug(s);
}
catch (IOException e)
{
e.printStackTrace();
}
p.destroy();
debug("Exit val is: " + p.exitValue());
}

public void debug(String a_str)
{
if (verbose)
{
System.out.println(this.getClass().getName() + ": " + a_str);
}
}

public static void main(String args[])
{
if (args.length < 2)
{
System.out.println("Usage: java RuntimeExecJar ");
System.exit(0);
}
RuntimeExecJar r = new RuntimeExecJar();
File dir = new File(args[1]);
if (!dir.isDirectory())
{
System.out.println(args[1] + " is not a directory");
System.exit(1);
}
String strCmd = "jar cvfM " + args[0] + " " + dir.getPath() + "/*";
r.debug("Cmd is: " + strCmd);
r.runExec(strCmd);
}
}

About | Sitemap | Contact