0

如何使用 AS3 adobe AIR 创建一个真正的新文本文件 (.txt)。大多数文章正在写入现有文本文件(文本文件已存在)。

像这样: 如何使用 Adob​​e Air 创建新的文件 txt

谢谢你。

4

1 回答 1

2
//create a reference to the file in the applicationStorage Directory 
//(for more directories, look at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html
var fileToCreate:File = File.applicationStorageDirectory;
fileToCreate          = fileToCreate.resolvePath("myfile.txt");

//create a filestream to write to the file
//the write and/or creating the file is done with the FileMode in the open() function
//look at the table that describes what FileMode does what here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileMode.html
var fileStream:FileStream = new FileStream();
fileStream.open(fileToCreate, FileMode.WRITE);

//write some string to the file
fileStream.writeUTF('this is a string to write to the file');

//finally, close the filestream
fileStream.close();

编辑:将文件模式从 READ 更改为 WRITE。READ 当然不会创建文件:)

于 2013-06-26T09:46:52.550 回答