大家好,我已经很努力地给android写了一个文件,到目前为止还没有成功。这是我正在使用的代码。
function writeAirFile():void
{
// Change the folder path to whatever you want plus name your mp3
// If the folder or folders does not exist it will create it.
var file:File = new File("/mnt/sdcard/new/new.apk");
//file.nativePath = "/mnt/sdcard/new/new.apk";
trace(file.nativePath);
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The file is written.");
trace(file.nativePath);
}
uts需要工作,但它不是。我已经添加了本地存储写入权限我需要帮助非常感谢大家的帮助!
指出自定义目录不是最佳实践,您可以使用File.applicationStorageDirectory
,因此无需担心安全和权限相关问题。
var file:File = File.applicationStorageDirectory.resolvePath("new/new.apk");
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The file is written.");
trace(file.nativePath); // you can find where it is stored.
建议始终使用异步模式文件操作,这样即使文件大小太大也不会发生UI冻结