有没有一种方法来读取在ActionScript 3英寸的本地文件,默默"'? [英] Is there a way to read local files in ActionScript 3 "silently"'?

查看:106
本文介绍了有没有一种方法来读取在ActionScript 3英寸的本地文件,默默"'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,因为某些设计限制,我必须这样做,在Flash中。此应用程序与另一个用C ++进行通信,而只是因为我需要一对夫妇的字符串,所以我想它会很容易,并写入到一个txt文件,并解析它。但我迄今为止发现的唯一的办法就是增加了浏览事件处理程序,并手动选择文件。这不适合我,我需要的文件读取自动给出一个路径,是这样的:

I'm developing an application and because of certain design restrictions I have to do it in Flash. This application communicates with another one done in c++, but just because I need a couple strings, so I thought it would be easy to write them to a .txt file and parse it. But the only way I've found so far is adding a browse event handler and select the file manually. That's no good for me, I need the file to be read automatically given a path, something like:

        var data:ByteArray = fileRef['C:\whateverPath'];
        var loader:Loader = new Loader();
        loader.loadBytes(data);

可以这样甚至可以做?

Can this even be done?

推荐答案

假设,因为这将运行使用的是AIR桌面上。如果是这样,你可以使用标准AIR文件API的像这样(假设该文件生命中的用户目录):

Assuming since this runs on the desktop you are using AIR. If so, you can use the standard AIR file APIs like so (this assumes the file lives in the user directory):

var file:File = File.userDirectory.resolvePath("myfilename.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readUTFBytes(file.size);
fileStream.close();

上面还假定文本文件为UTF-8 EN codeD。如果不是,也有FileStream类其他读取方法。

The above also assumes the text file is UTF-8 encoded. If not, there are other read methods in the FileStream class.

AIR还可以访问其他目录,当然。例如,为了获得在C盘根文件:在Windows驱动器:

AIR also has access to other directories, of course. For instance, to get a file in the root of the C: drive on windows:

var file:File = new File("C:/mytextfile.txt");

这篇关于有没有一种方法来读取在ActionScript 3英寸的本地文件,默默"'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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