I currently use two methods to output files to the local in flex, namely File and FieldRefreence
Example:
var exportString:String = "This is a test"
1. File output
var ff:File = File.desktopDirectory.resolvePath("Progress.CSV"); ff.addEventListener(Event.SELECT,exportCSVSelectedHandler); ff.browseForSave("选择路径"); private function exportCSVSelectedHandler(event:Event):void { var dir:String = event.target.nativePath; var writeStream:FileStream = new FileStream(); writeStream.open(new File(dir),FileMode.WRITE); var content:String = "jhfdklahflaksjdhflkasjhflaskjhlf\n"; writeStream.writeMultiByte(content,'utf-8'); writeStream.close(); }
2. FileReference output
var content:String = "jhfdklahflaksjdhflkasjhflaskjhlf\n"; var f:FileReference = new FileReference(); f.save(content,"1.csv");
The difference between File and FileReference is that File can specify the encoding format of the document, while FileReference is relatively simple to use
For more related articles on two methods of Flex outputting files to local area, please pay attention to the PHP Chinese website!