0
如何使用AS3 adobe AIR創建REALY NEW文本文件(.txt)。大多數文章正在寫入現有的文本文件(文本文件已經存在)。如何使用Adobe AIR創建新的txt文件
像這樣的: How to create new File txt by using Adobe Air
謝謝。
如何使用AS3 adobe AIR創建REALY NEW文本文件(.txt)。大多數文章正在寫入現有的文本文件(文本文件已經存在)。如何使用Adobe AIR創建新的txt文件
像這樣的: How to create new File txt by using Adobe Air
謝謝。
//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不會創建課程文件:)
沒有創建,抱歉。 >我將'applicationStorageDirectory'更改爲'applicationDirectory'。 >創建新的空氣應用程序,保存它,Ctrl-輸入它(用於測試),並出現錯誤: > SecurityError:fileWriteResource \t at flash.filesystem :: FileStream/open() \t at CreateTXTfile_AIR_fla :: MainTimeline/frame1 ()[CreateTXTfile_AIR_fla.MainTimeline ::幀1:18] \t在運行時:: ContentPlayer/loadInitialContent() \t在運行時:: ContentPlayer/playRawContent() \t在運行時:: ContentPlayer/playContent() \t在運行時: :AppRunner/run() \t at ADLAppEntry/run() \t at global/runtime :: ADLEntry() –
You無法以無管理員權限寫入applicationDirectory。將其更改回applicationStorageDirectory以查看腳本是否可用 – Marijn
好吧,我將其更改回applicationStorageDirectory。沒有錯誤,但仍然不起作用。沒有創建文件。 :( –