Java generates an XML file and compresses the file into zip format and then writes to the hard drive

Source: Internet
Author: User

To make some data into an XML file, but not on your hard disk, compress the file into a zip format and write it to your hard disk. The final result is: The hard disk has a test.zip file, decompression after the Test.xml file.
 
Add the. xml suffix to the name after you declare zipentry ... The
example follows: Public

static void Main (string[] arg) throws exception{

String xml;  
 * *  generates your XML data, which exists in string XML.
 */

Zipoutputstream zipout = new Zipoutputstream (New FileOutputStream ("D://test.zip"));
Declaration Zipoutputstream, used to output zip files.

ZipEntry entry = new ZipEntry ("Test.xml");
Statement ZipEntry

zipout.putnextentry (entry);
Add entry to the ZipOut.

DataOutputStream Dataos = new DataOutputStream (zipout);
The Zipoutputstream is packaged using DataOutputStream.
Dataos.writeutf (GD);
Output zip file.
dataos.close ();
} 

After running, there is a test.zip file in D disk, which contains a test.xml file.

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.