Java Zip String addStringToZip(String text, String entryName, ZipOutputStream zOut)

Here you can find the source of addStringToZip(String text, String entryName, ZipOutputStream zOut)

Description

Adds a String as a field entry to an already opened ZipOutputStream

License

Open Source License

Parameter

Parameter Description
text a parameter
entryName a parameter
zOut a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void addStringToZip(String text, String entryName, ZipOutputStream zOut) throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.StringReader;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    /**// ww  w. ja  v a 2 s.c  om
    * Adds a String as a field entry to an already opened ZipOutputStream
    * @param text
    * @param entryName
    * @param zOut
    * @throws IOException
    */
    public static void addStringToZip(String text, String entryName, ZipOutputStream zOut) throws IOException {
        BufferedReader reader = new BufferedReader(new StringReader(text));

        ZipEntry zipEntry = new ZipEntry(entryName);

        zOut.putNextEntry(zipEntry);

        int i;
        while ((i = reader.read()) != -1) {
            zOut.write(i);
        }
        zOut.closeEntry();
    }
}

Related

  1. generateZip(String kmlContents)
  2. zip(String content)
  3. zip(String content)
  4. zip(String str)