java zip - create text file of String and zip it

Create a text file with some string (without temporary file) and zip it : working source code java

 private static void zip_single() throws Exception {
  final StringBuilder sb = new StringBuilder();
  sb.append("Test String that goes into text file inside zip");

  final File f = new File("");
  final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f));
  ZipEntry e = new ZipEntry("inside_text_file.txt");

  byte[] data = sb.toString().getBytes();
  out.write(data, 0, data.length);


Call as :
 public static void main(String[] args) throws Exception {

For creating text files from List of string and zip them - see my earlier post 

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...