Java Jar Zip File addFileToJar(File file, ZipOutputStream zipStream, String path)

Here you can find the source of addFileToJar(File file, ZipOutputStream zipStream, String path)

Description

add File To Jar

License

Open Source License

Declaration

private static void addFileToJar(File file, ZipOutputStream zipStream,
            String path) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    private static void addFileToJar(File file, ZipOutputStream zipStream,
            String path) throws IOException {
        FileInputStream fin = new FileInputStream(file);

        int bufSize = 1024;
        byte ipBuf[] = new byte[bufSize];
        int lenRead = 0;

        String filename = path + file.getName();
        zipStream.putNextEntry(new ZipEntry(filename));

        while ((lenRead = fin.read(ipBuf)) > 0) {
            zipStream.write(ipBuf, 0, lenRead);
        }//w  w w. j  a v a  2 s  .c o m

        zipStream.closeEntry();
        fin.close();
    }
}

Related

  1. addFileToJar(File baseDir, File src, JarOutputStream zOut)
  2. addFileToJar(File fileOrDirectoryToAdd, File extractedJarPath, JarOutputStream target)
  3. addFileToJar(JarOutputStream jar, InputStream file, String path)
  4. addJar(File path)
  5. addJarLibralyClassPath(Object classLoaderMakedObject, File jarPath)