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.