在flex中輸出檔案到本地目前我用到兩種方法,分別是File和FielRefreence
例子:
var exportString:String = "這就是一個測試"
1、File輸出
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輸出
var content:String = "jhfdklahflaksjdhflkasjhflaskjhlf\n"; var f:FileReference = new FileReference(); f.save(content,"1.csv");
File和FileReference兩者的差異在於File可以指定文檔的編碼格式,而FileReference使用起來相對簡單
更多Flex 輸出文件到本地的兩種方法相關文章請關注PHP中文網!