【发布时间】:2011-02-22 13:19:19
【问题描述】:
如何将字符串保存到applicationdirectory 中的文件(file.superlongextention) 并获取其在硬盘驱动器上的真实位置(如C:/files/...)?
【问题讨论】:
标签: apache-flex flash actionscript-3 file air
如何将字符串保存到applicationdirectory 中的文件(file.superlongextention) 并获取其在硬盘驱动器上的真实位置(如C:/files/...)?
【问题讨论】:
标签: apache-flex flash actionscript-3 file air
但您可以将文件保存在应用程序目录中
var appPath:File = File.applicationDirectory.resolvePath("");
var fromUserPath:File = File.userDirectory.resolvePath(appPath.nativePath);
感谢 Tanel Teemusk
http://blog.teemusk.com/2011/10/writing-to-applicationdirectory-with-adobe-air/
【讨论】:
出于安全原因,您不能写入Application directory(可以进行测试,但不建议这样做)。
您可以写入应用程序存储目录来存储您的应用程序数据。
要获取文件的路径,请使用nativePath。
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import mx.controls.Alert;
// get a file reference to the storage directory
var file:File=File.applicationStorageDirectory.resolvePath("myfile.withextension");
// create a file stream
var fs:FileStream=new FileStream();
// open the stream for writting
fs.open(file, FileMode.WRITE);
// write the string data down to the file
fs.writeUTFBytes("my string to save");
// ok close the file stream
fs.close();
// show the path to the file we have saved using Alert
Alert.show(file.nativePath);
【讨论】: