Java batch download to generate ZIP files

Source: Internet
Author: User

 

Download the two files at the same time using the following code:

ImportJava. Io. file;
ImportJava. Io. fileinputstream;

ImportJava. Io. fileoutputstream;

ImportJava.util.zip. zipentry;

ImportJava.util.zip. zipoutputstream;

Public
Class
Zipoutputstreamdemo {


Public
Static
Void
Main (string [] ARGs)
ThrowsException {


Byte[] Buffer =
New
Byte
[1024];


// The generated ZIP file name is demo.Zip

String strzipname =
"Demo.zip ";

Zipoutputstream out =
NewZipoutputstream (New
Fileoutputstream (strzipname ));


// Result of the two files to be downloaded at the same time.Txt
, Source.Txt

File [] file1 = {New
File ("result.txt "),New
File ("source.txt ")};


For(Int
I = 0; I <file1.length; I ++ ){

Fileinputstream FCM =
NewFileinputstream (file1 [I]);

Out. putnextentry (New
Zipentry (file1 [I]. getname ()));


IntLen;


// Read the content of the object to be downloaded and package itZipFile


While(LEN = FCM. Read (buffer)> 0 ){

Out. Write (buffer, 0, Len );

}

Out. closeentry ();

FCM. Close ();

}

Out. Close ();

System.Out. Println ("demo.zip created ");

}

} There is also the following reference: http://wjhcomputer.iteye.com/blog/1000333http://topic.csdn.net/u/20070209/09/ed602597-c693-4ec1-b9eb-51d35e493d10.htmlhttp://topic.csdn.net/u/20100727/14/6b86a6a8-5ee4-4d3b-ae5e-004eead66fde.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.