在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使用起来相对简单