我有一个用户键入的字符串,我想将其保存到用户硬盘上的文件中.你能做到吗?如果是这样,怎么样?
是的,你可以使用FileReference.这基本上就是这样做的:
var bytes:ByteArray = new ByteArray(); var fileRef:FileReference=new FileReference(); fileRef.save("fileContent", "fileName");
看起来不太难,是吗?以下是关于它的视频教程:
http://www.gotoandlearn.com/play?id=76
和文件:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
希望有所帮助.
由于我有一个函数将字节输出到文件中(因为我正在使用位图执行某些操作),所以我重复使用它来输出字符串,如下所示:
var filename:String = "/Users/me/path/to/file.txt"; var byteArray:ByteArray = new ByteArray(); byteArray.writeUTFBytes(someString); outFile(filename, byteArray); private static function outFile(fileName:String, data:ByteArray):void { var outFile:File = File.desktopDirectory; // dest folder is desktop outFile = outFile.resolvePath(fileName); // name of file to write var outStream:FileStream = new FileStream(); // open output file stream in WRITE mode outStream.open(outFile, FileMode.WRITE); // write out the file outStream.writeBytes(data, 0, data.length); // close it outStream.close(); }