在Adobe AIR中写入文件 [英] write file in adobe air for android

查看:197
本文介绍了在Adobe AIR中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello evrey身体我已经很努力地写一个文件到android,至今没有secceus。
这是我正在使用的代码。

pre $函数writeAirFile():void
{
//将文件夹路径更改为任何你想要的名称你的mp3
//如果文件夹或文件夹不存在,它将创建它。
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(文件被写入);
trace(file.nativePath);


$ / code $ / pre

需要工作,但事实并非如此。
i已经为本地留言添加了许可
请帮助我
感谢你们所有人的帮助!

解决方案

指出自定义目录不是最佳实践,可以使用 File.applicationStorageDirectory ,因此不需要担心安全性和权限相关的问题。 p>

  var file:File = File.applicationStorageDirectory.resolvePath(new / new.apk); 
fileStream.open(file,FileMode.WRITE);
fileStream.writeBytes(fileData,0,fileData.length);
fileStream.close();
trace(文件被写入);
trace(file.nativePath); //你可以找到它的存储位置

建议始终使用异步模式文件操作,这样即使文件大小也不会发生UI冻结大。


hello evrey body i have try really hard to write a file to android and so far no secceus. this is the code i am using.

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 need to work but it is not. i already add th permission for local storge writing please i need help thanks a lot for all of you for helping!

解决方案

Point out custom directory is not best practices better you can use File.applicationStorageDirectory so no need worry about security and permission related issue.

    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.

Suggestion always use Async mode file operation so that UI freeze won't happen even if file size is too large.

这篇关于在Adobe AIR中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆