How do you programmatically create a JAR file?

Heinrich Soebke

File outFile = new File(outPath);

BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(outPath));
JarOutputStream jo = new JarOutputStream(bo);

String act = f.getPath();
BufferedInputStream bi = new BufferedInputStream(new FileInputStream(act));

JarEntry je = new JarEntry(act);
jo.putNextEntry(je);

byte[] buf = new byte[1024];
int anz;
     
while ((anz = bi.read(buf)) != -1) {
  jo.write(buf, 0, anz);
}

bi.close();
jo.close();
bo.close();
See also http://developer.java.sun.com/developer/technicalArticles/Programming/compression/.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact