Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to convert multiple files in java to .zip format
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sangram
How to convert multiple files in java to .zip format
1 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners


i receive multiple files from a remote URL as

for (String reportid : reportList) {  
inputStream = AWSFileUtil.getInputStream(  
                        AWSConnectionUtil.getS3Object(null),  
                        "cdn.generalsentiment.com", filePath);  
}

i want to convert the data from inputStream into Zip Stream and so as to make it available for download.


Advertisement
View Answers

February 6, 2012 at 11:06 AM


import java.io.*;
import java.util.zip.*;

public class CreateZip {
  public static int buffer = 10240;
  protected void createZip(File zipFile, File[] listFiles) {
    try {
      byte b[] = new byte[buffer];
      FileOutputStream fout = new FileOutputStream(zipFile);
      ZipOutputStream out = new ZipOutputStream(fout);
      for (int i = 0; i < listFiles.length; i++) {
        if (listFiles[i] == null || !listFiles[i].exists()|| listFiles[i].isDirectory())
      System.out.println();
        ZipEntry addFiles = new ZipEntry(listFiles[i].getName());
        addFiles.setTime(listFiles[i].lastModified());
        out.putNextEntry(addFiles);

        FileInputStream fin = new FileInputStream(listFiles[i]);
        while (true) {
          int len = fin.read(b, 0, b.length);
          if (len <= 0)
            break;
          out.write(b, 0, len);
        }
        fin.close();
      }
      out.close();
      fout.close();
      System.out.println("Zip File is created successfully.");
    } catch (Exception ex) {}
  }
  public static void main(String[]args){
    CreateJar jar=new CreateJar();
    File folder = new File("C://Answers//Examples");
      File[] files = folder.listFiles();
    File file=new File("C://Answers//Examples//Examples.zip");
    jar.createZip(file, files);
  }
}


Related Tutorials/Questions & Answers:
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...); } i want to convert the data from inputStream into Zip Stream and so
How to download files from server to local disk using ZIP format in JSP page - JSP-Servlet
How to download files from server to local disk using ZIP format in JSP page  hi i have an application to upload and download multiple files. As i... disk creting ZIP format for all files .how can create ZIp for all files pls help me
Advertisements
How to convert EBCDIC format value into ASCII format value in java
How to convert EBCDIC format value into ASCII format value in java  how to convert EBCDIC data format into ASCII format data using java Use Case:I my file contains ASCII format values as well as EBCDIC format values.I need
Java zip package - Learn how to use java zip package.
of java library. We will also learn how to use the zip API to create and read the zip and gzip files within java program. The zip format is very easy method... the archive files. The java zip package provides the API for reading and writing
How to convert excel file int xml format in java
How to convert excel file int xml format in java  How to read excel file(xls) which is stored in any directory(D://) and convert it into xml format in java and place in any directory(E://).Can any body provide the code
convert zip file to byte array
convert zip file to byte array  Hi,How to convert zip file to byte array,can you please provide program?? Thanks, Ramanuja
Java Util Zip. Zip files/folders inside a folder, without zipping the original source folder.
Java Util Zip. Zip files/folders inside a folder, without zipping the original...) throws Exception { ZipOutputStream zip = null; FileOutputStream fileWriter = null; fileWriter = new FileOutputStream(destZipFile); zip = new
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information.... We have to find the students according to particular school from all the files
How to Convert Text Files into Gzip File
How to Convert Text Files into Gzip File  Hi, I am developing a small application using PHP language. The real problem is that how do i convert the text files into gzip file. how can i solve the problem.... Tnanks
Java Zip Package
to include classes for manipulating ZIP files as part of the standard Java APIs... for writing files in the ZIP file format.  ... Java Zip Package      
convert a file .doc to .zip
convert a file .doc to .zip  hiii, I uploaded a file with extension .doc now i required with .zip   Hi Friend, Try the following code: 1)page.jsp: <%@ page language="java" %> <HTml> <HEAD><
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... these two files and store in oracle database as: VendorID,Name,Address and plz
How can I Convert my Image Files to Text Files? - IDE Questions
How can I Convert my Image Files to Text Files?  How can I Convert my Image Files to Text Files
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
Java file zip
Java file zip In this section, you will learn how to create a zip file. The ZIP file format is used for the distribution and storage of files... an output stream filter for writing files in the ZIP file format. Then we have
convert data format sql
convert data format sql  convert data format sql
convert .txt file in .csv format - Java Beginners
convert .txt file in .csv format  Dear all, I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have different names and values. e.g. start: id:XXXX name:abc address:xyz
How to convert many class files into one exe file?
How to convert many class files into one exe file?  How to convert class files into one exe file? I have done my project in java.i want to know how to convert it into .exe file? plz reply fast. Thnx in Advance. Happy Pongal
How to convert many class files into one exe file?
How to convert many class files into one exe file?  How to convert class files into one exe file? I have done my project in java.i want to know how to convert it into .exe file? plz reply fast. Thnx in Advance. Happy Pongal
How to convert into to String in Java?
How to convert into to String in Java?  Hi, How to convert into to String in Java? Thanks
Unzip a ZIP File
the following example. This program shows you how to extract files from a zip file in which many different files are stored in compressed format and make a single zip... class gets the files entries of the zip file format
How to extract zip file in java.
How to extract zip file in java. In this Example, we will discuss how to extract a ZIP file. We will use ZipInputStream class for creating input stream that take input from ZIP file. The ZipInputStream class is available
how to create a zip by using byte array
how to create a zip by using byte array  hi, How to convert byte array to zip by using java program.can u plz provide it...... Thanks, krishna
Renaming multiple files
Renaming multiple files  Hi, I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705..., 2RohitBBorse.mp4, 3_RohitBBorse.mp4, .... Please suggest me through java program how I can
Reading multiple xml files
Reading multiple xml files  How can we read many xml files from a folder? The same procedure as that of "listfiles
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
How to make a zip file in java
Description: In this example we will discuss about how to create zip file from... zip file. Code: import java.io.*; import java.util.zip....;SuccessFully converted In Zip Format");     
Java show files in tree format
Java show files in tree format In this section you will learn how to display the whole file system in tree format. Description of code: The java.swing... example, we have used JTree class to show the whole files in a systematic way
How to convert string to byte in Java
How to convert string to byte in Java  How to convert string to byte in Java
Advertisements
 

 

 

DMCA.com