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



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

Have Programming Question? Ask it here!
 
 
 


sangram
How to convert multiple files in java to .zip format
1 Answer(s)      2 years and 6 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><
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 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
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
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
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
convert data format sql
convert data format sql  convert data format sql
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");     
How to convert string to byte in Java
How to convert string to byte in Java  How to convert string to byte in Java
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 Visual c++ to java - Java Beginners
how to convert Visual c++ to java  Hi Sakthi here.. How to convert Visual c++ codings to Java codings.. Does both have any similarity in library files
how to convert string to image in java
how to convert string to image in java  how to convert string to image in java? I know we need to convert image to a byte array at some point in my application but do not know how to convert a image into byte string. Please
Create zip file in Java
. You will also learn how to create a zip file from any file through the java... applications. It is also possible to zip and unzip the files from your Java applications. This program shows you how to zip any file through your java
Copy multiple files
Copy multiple files        In this section, you will learn how the data of multiple files.... For copping the data of multiple file, you need all files in a specified directory where
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?  how to convert the entire column field which... got to know how to convert for a single by using [18-10-2012 20:10:25] r
how to covert JPG format to Binary formart using java code..
how to covert JPG format to Binary formart using java code..  convert JPG format to Binary formart How can i convert JPG format to Binary format using java code plz help me out
How to zip a file using javascrip?
How to zip a file using javascrip?  hi.. can anyone tell me How to zip a file using javascrip
Creating a ZIP file in Java
of data compression. Zip file contains many files in compressed format. You can say the files are stored in the zip format with compression. The file which... Creating a ZIP file in Java   
Dynamic include of multiple files
Dynamic include of multiple files  I want to include a series of small files, based on a string. For instance, if the string was: String fileString="a b c d e"; I would split it into an array, fileArray, and do something like
convert JPG format to Binary formart - IDE Questions
convert JPG format to Binary formart  How can i convert JPG format to Binary format in visual basic ? is there any code for that can work? thanks Mohamad
how to backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external drive.   hi friend, Try the following code may, this will be helpful
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
How to delete files in Java?
Delete a File using File Class Object       Delete a File using File Class Object In this section, you will learn how to delete a file. 
Merging multiple PDF files - Framework
Merging multiple PDF files  I m using the iText package to merge pdf files. Its working fine but on each corner of the merged filep there is some... the files are having different font.Please help
Uploading Multiple Files Using Jsp
to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files... Uploading Multiple Files Using Jsp  
How to create a zip file and how to compare zip size with normal text file
How to create a zip file and how to compare zip size with normal text file  Hi, how are you?I hope you are fine.I want program like how to create zip... by Roseindia. http://www.roseindia.net/java/example/java/io
How to convert http website into Https from java?
How to convert http website into Https from java?  could any one tell me how to convert http website into Https from java
Advertisements
 

 

 

DMCA.com