Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
satishmukku
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel
Accepted Solution

reading data from files

hi to every one,

 

 I am trying to aceess data from files and want to display them in one by one.

 

when i am debug my program i got an error that no such file exists,even iam storing it,

 

here is my code can any one help me to find out the problem

 

thanks in advance.

 

var myFile:File = File.applicationStorageDirectory.resolvePath("abc.txt");
		myFile.createDirectory();
		
			if(myFile.exists)
				Alert.showAlertDialog("File Found");//i got output as file not found
			else
				Alert.showAlertDialog("File Not Found");
			
	var fileStream:FileStream = new FileStream(); 
	fileStream.open(myFile, FileMode.READ);

 

Please use plain text.
Contributor
satishmukku
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

Reading data from files

var myFile:File = File.applicationStorageDirectory.resolvePath("abc.txt");
			
		if(myFile.exists)
			Alert.showAlertDialog("File Found");
		else
			Alert.showAlertDialog("File Not Found"); // this stmt is executing
			
			var fileStream:FileStream = new FileStream(); 
			fileStream.open(myFile, FileMode.READ);

 

Please use plain text.
Developer
pyth
Posts: 462
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: reading data from files

[ Edited ]

that's because you try to create a directoy when a file is expected

 

either you should do this

 

var myFile:File = File.applicationStorageDirectory.resolvePath("abc.txt");
		var fs:FileStream;
		
			if(myFile.exists)
				//Alert.showAlertDialog("File Found");//i got output as file not found
trace("file found");
 else { //Alert.showAlertDialog("File Not Found"); fs = new FileStream(); fs.open(myFile, FileMode.WRITE); fs.close(); //now you have your file } var fileStream:FileStream = new FileStream(); fileStream.open(myFile, FileMode.READ);

 or, if you want to have a directory

 

var directory:File = File.applicationStorageDirectory.resolvePath("data/myDirectory/");
if (!directory.exists)
     directory.createDirectory();

var list:Array = directory.getDirectoryListing();
            for (var i:uint = 0; i < list.length; i++) {
                trace("File found: " + list[i].nativePath);
            }

 

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Contributor
satishmukku
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

Re: reading data from files

actually i didnt use the creatredirectory() method, that was in comments block, so no effefct to code,

 

your code is similar to my code, there is no difference,

 

but the problem is my application cant get the local stored file, 

 

can any one pls tell me to where i need to store the my file.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: reading data from files

If it is files that you dont want the user to have access to (e.g. preferences), then the app-storage directory is fine. If you want the user to have access to it and/or what the files to remain on the device if the app is removed, then the documents directory is where you want to place them. If you do put them in the documents directory, then you need to make certain you allow file access/permission in the bb app xml file.
Please use plain text.
Developer
pyth
Posts: 462
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: reading data from files

you should look closer, there is the difference that i create the file if it doesn't exist. i open a filestream directly, store it and close it again so that the file exists

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Contributor
satishmukku
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

Re: reading data from files

Hi Sir,

I am got the solution,

the problem is i am using ApplicationStorageDirectoy that was not accepting my file, applicationDirectory Is suitable for accesing the data.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: reading data from files

Ah, so the file is installed with the app. Missed that part.
Please use plain text.