Flex:生成zip文件
采用aszip代码库生成,以下是测试代码,生成多个目录多个文件
<?xmlversion="1.0" encoding="utf-8"?>
<s:Applicationxmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"minHeight="600">
<fx:Script>
<![CDATA[
importmx.core.ByteArrayAsset;
importorg.aszip.saving.Method;
importorg.aszip.zip.ASZip;
private function Init():void
{
}
[Embed(source="test.xml",mimeType="application/octet-stream")]
public varASSET1:Class;
private functionGenerateZip():void
{
varzip:ASZip = new ASZip();
zip.addDirectory("folder1");
zip.addDirectory("folder2");
zip.addDirectory("folder2/folder3");
zip.addDirectory("folder3/folder3");
zip.addDirectory("folder3/目录3");
varfileData:ByteArray = newByteArray();
fileData.writeUTF("HelloWorld!");
zip.addFile(fileData, "folder1/helloworld.txt");
varxmlBytes:ByteArrayAsset = new ASSET1()asByteArrayAsset;
zip.addFile(xmlBytes, "folder2/中文文件名.xml");
varzipData:ByteArray = zip.saveZIP(Method.LOCAL);
varfile:FileReference = newFileReference();
file.save(zipData, "Test.zip");
}
]]>
</fx:Script>
<s:Buttonlabel="Test" click="GenerateZip()"/>
</s:Application>
原版aszip不支持中文目录和中文文件名,现已修正,下载链接如下:
??