是否有可能加载本地文件,而无需要求用户浏览到它第一次在AIR应用程序?有可能、到它、应用程序、加载

2023-09-08 15:20:53 作者:从此封心

我正在写一个小应用程序为我自己和,而不是使用一个数据库,我想只是用Excel来存储我的本地文件系统中的数据量小我。我希望能够加载数据,而不必使用典型的的FileReference浏览()方法,这纯粹是讨厌做我每次使用应用​​程序的时间。

在code以下似乎找到该文件细如下面的file.exists方法大多数的其他属性似乎是正确的,但在 file.data 始终为空。

我猜这是一个安全问题,这就是为什么我遇到了这个问题,但我认为我会问,看看是否有其实解决这个问题的方法。

  var文件:文件=新的文件(FULLPATH +\\+ currentFolder +名.txt);
如果(file.exists){
     VAR的字节数组:ByteArray的= file.data;
}
 

解决方案

如果你想读一个文件的内容,请使用以下code:

  VAR流:的FileStream =新的FileStream();
stream.open(这里有些路径,FileMode.READ);
VAR的FileData:字符串= stream.readUTFBytes(stream.bytesAvailable);
跟踪(的FileData);
 
APP产品设计中常见的全局状态

中的数据属性是从FileReference类继承的,它会被填充后,才一个电话负载(见链接)。

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.

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);

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