如何使用AS3 adobe AIR创建REALY NEW文本文件(.txt)。大多数文章都写入了现有的文本文件(文本文件已经存在)。
像这样一个: How to create new File txt by using Adobe Air谢谢。
答案 0 :(得分: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不会创建文件:)