playbook: create a new folder and save some data
I need to create a new folder and save some data in it. The code is as follow:
var list:Array=reader.getEntries();
for(var i:uint=0;i < list.length;i++)
{
var bytes:ByteArray=reader.unzip(list[i]);
var fileStream:FileStream=new FileStream();
fileStream.open(dir.resolvePath( list[i].getFilename() ),FileMode.WRITE);
fileStream.writeBytes(bytes,0,bytes.length);
}
fileStream.close();
The code below is for creating the directory dir:
dir=File.applicationStorageDirectory.resolvePath(dirname);
dir.createDirectory();
But whenever I run this code I am getting this
Error #3001: File or directory access denied.
I have given the reqd permissions in the blackberry_tablet.xml i.e. access_shared.
P.S. I am using 开发者_开发知识库coltware_airxzip.swf for extract files from a zip archive which I am storing in the array list.
I know you said you checked the permissions but I would check them again. Also, check the file directory and file name value and make sure it does not contain illegal file name characters. For example, a file name like this, ")%@*)!~-`.txt" might cause errors.
Also, check the user has not disabled application permissions (shouldn't be an issue in development).
To eliminate the possibility it is the zip library see if you can create simple file entries:
for(var i:int;i < 5;i++)
{
var fileStream:FileStream = new FileStream();
var file:File = File.applicationStorageDirectory.resolvePath( "test_"+i+".txt" );
// if in directory attempt to create it first - something like this for the directory
// file = !file.exists ? file.createDirectory() : file;
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTFBytes("test data");
fileStream.close();
// if space available is not 0 then that is good indication file was created or saved
// of course so is file.exists
trace("file exists = " +file.exists);
trace("Space available = " +file.spaceAvailable);
}
Note: I have this same issue right now except no error message. It says the file and directory are created and shows the native path as this:
/accounts/1000/appdata/MyApplication.debug.testDev_Maker_debug533b7b57/data/MyApplication/file_1.txt
and app storage path as:
app-storage:/MyApplication/file_1.txt
However, I can't find the file in either AIR Browser or RIM File Manager. So I'm not sure what the issue is but I think it may be that it's not writing it because it's in debug mode. I'll be able to provide confirmation once it's released.
精彩评论