Home  >  Article  >  php教程  >  Two methods for Flex to output files to local

Two methods for Flex to output files to local

高洛峰
高洛峰Original
2016-12-27 16:43:461202browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn