Posts Tagged ‘file’

ZipFileReader class can NOT make directory or file.
So you should make directory or file according to ZipEntry.isDirectory() method.

var file:File = File.desktopDirectory.resolvePath("sample.zip");
			
var reader:ZipFileReader = new ZipFileReader();
reader.open(file);
var fileList:Array = reader.getEntries();
var baseDir:File = File.documentsDirectory();

for each(var entry:ZipEntry in fileList){
	var filename:String = entry.getFilename();
	
	if(entry.isDirectory()){
		//  If entry is directory 
		var dir:File = baseDir.resolvePath(filename);
		dir.createDirectory();
	}
	else{
		var unzippedBytes:ByteArray = reader.unzip(entry);
		var file:File = baseDir.resolvePath(filename);
		var fs:FileStream = new FileStream(FileMode.WRITE);
		fs.writeBytes(unzippedBytes,0,unzippedBytes.length);
		fs.close();
	}
}
reader.close();
RSS
Add to Google
2017年2月
« 2月    
 1234
567891011
12131415161718
19202122232425
262728