Java Utililty Methods Zip File

List of utility methods to do Zip File

Description

The list of methods to do Zip File are organized into topic(s).

Method

voidzipFile(File source, File target)
Zip file.
FileOutputStream fos = new FileOutputStream(target);
ZipOutputStream zos = new ZipOutputStream(fos);
FileInputStream fis = new FileInputStream(source);
BufferedInputStream bis = new BufferedInputStream(fis);
ZipEntry entry = new ZipEntry(source.getCanonicalFile().getName());
zos.putNextEntry(entry);
byte[] barray = new byte[1024];
int bytes;
...
voidzipFile(File source, File target)
Simple method to zip up a file
FileOutputStream fo = new FileOutputStream(target);
ZipOutputStream zo = new ZipOutputStream(fo);
zo.setMethod(ZipOutputStream.DEFLATED);
FileInputStream fi = new FileInputStream(source);
BufferedInputStream bi = new BufferedInputStream(fi);
ZipEntry ze = new ZipEntry(source.getName());
zo.putNextEntry(ze);
byte[] dt = new byte[1024];
...
voidzipFile(File source, String basePath, ZipOutputStream zos)
zip File
File[] files = null;
if (source.isDirectory()) {
    files = source.listFiles();
} else {
    files = new File[1];
    files[0] = source;
String pathName;
...
FilezipFile(File sourceFile)
Compress a file or recursively compress all files of a folder.
File zippedFile = new File(sourceFile.getAbsolutePath() + ".zip");
zipFile(sourceFile, zippedFile);
return zippedFile;
voidzipFile(File zipfile, ZipOutputStream zos, String name)
zip File
FileInputStream fis = new FileInputStream(zipfile);
try {
    ZipEntry anEntry = new ZipEntry(name);
    if (DEBUG)
        System.out.println("Add file : " + name);
    zos.putNextEntry(anEntry);
    byte[] readBuffer = new byte[BUFFER_SIZE];
    for (int bytesIn = fis.read(readBuffer); bytesIn != -1; bytesIn = fis.read(readBuffer)) {
...
voidzipFile(final File source)
Zip a single file into a compressed ZIP archive.
zipFile(source, new File(source.getAbsolutePath() + ZIP_SUFFIX));
voidzipFile(final File target, final ZipOutputStream zip, final File file, final String path)
zip File
if (!file.equals(target)) {
    final ZipEntry ze = new ZipEntry(path);
    ze.setTime(file.lastModified() + 1999);
    ze.setMethod(ZipEntry.DEFLATED);
    zip.putNextEntry(ze);
    final FileInputStream in = new FileInputStream(file);
    try {
        int bufsize = 8 * 1024;
...
voidzipFile(String filedir, String zippath)
zip File
@SuppressWarnings("rawtypes")
List fl = getAllFilePath(filedir);
File f = new File(zippath);
try {
    FileOutputStream fo = new FileOutputStream(f);
    ZipOutputStream zo = new ZipOutputStream(fo);
    for (int i = 0; i < fl.size(); i++) {
        File ff = (File) fl.get(i);
...
voidzipFile(String filePath, int iBaseFolderLength, ZipOutputStream jos, CRC32 crc)
Add a file into a zip.
try {
    FileInputStream fis = new FileInputStream(filePath);
    BufferedInputStream bis = new BufferedInputStream(fis);
    String fileNameEntry = filePath.substring(iBaseFolderLength).replace(File.separatorChar, '/');
    ZipEntry fileEntry = new ZipEntry(fileNameEntry);
    jos.putNextEntry(fileEntry);
    byte[] data = new byte[1024];
    int byteCount;
...
voidzipFile(String filePath, String fileName)
zip File
String[] filenames = new String[] { fileName };
byte[] buf = new byte[1024];
String outFilename = fileName + ".zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(filePath + "/" + outFilename));
for (int i = 0; i < filenames.length; ++i) {
    FileInputStream in = new FileInputStream(filePath + "/" + filenames[i]);
    out.putNextEntry(new ZipEntry(filenames[i]));
    boolean len = false;
...