应用程序中浏览到它

应用程序中浏览到它

本文介绍了是否可以加载本地文件而不必要求用户首先在 AIR 应用程序中浏览到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在为自己编写一个小型应用程序,而不是使用数据库,我只想使用 Excel 来存储我在本地文件系统上的少量数据.我希望能够加载该数据而不必使用典型的 FileReference browse() 方法,因为每次使用该应用程序时都会很烦人.

I'm writing a small application for myself and instead of using a database I'd like to just use Excel to store the small amount of data I have on my local file system. I want to be able to load that data without having to use the typical FileReference browse() method as it would just be annoying to do every time I use the application.

下面的代码似乎发现文件很好,因为下面的 file.exists 方法和大多数其他属性似乎是正确的,但 file.data 始终为空.

The code below seems to find the file fine as the file.exists method below and most of the other attributes seem to be correct but the file.data is always null.

我猜这是一个安全问题,这就是我遇到这个问题的原因,但我想我会问一下,看看实际上是否有办法解决这个问题.

I'm guessing this is a security issue and that's why I'm running into this problem but I thought I'd ask and see if there is in fact a way around this problem.

var file:File = new File(fullPath + "\\" + currentFolder + ".txt");
if(file.exists) {
     var byteArray:ByteArray = file.data;
}

推荐答案

如果要读取文件的内容,请使用以下代码:

If you want to read the content of a file, use the following code:

var stream:FileStream = new FileStream();
stream.open("some path here", FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);

数据属性继承自 FileReference 类,只有在加载调用后才会填充(请参阅此 link).

The data property is inherited from FileReference class and it will be populated only after a load call (see this link).

这篇关于是否可以加载本地文件而不必要求用户首先在 AIR 应用程序中浏览到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:31