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
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel
Accepted Solution

Problem With files concept

hi everyone, 

 

Can any any one explain how to acees files, I am geting the error when i used to access the data from files

 

pls help me, iam w8ng,

 

here is my code

var myFile:File = File.applicationStorageDirectory.resolvePath("sample.txt");
		var fs:FileStream;
		
		if(myFile.exists)
			Alert.showAlertDialog("File Found");
		else {
			Alert.showAlertDialog("File Not Found");
		}
		
		var fileStream:FileStream = new FileStream(); 
		fileStream.open(myFile, FileMode.READ);
		
		var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);  
		
		fileStream.close();

 in the above code i got output as file not found.

i stored the file in the src folder in the project.

Developer
Posts: 1,269
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Problem With files concept

So your file only exists as a result of the app being installed, then, vs. being created when the app runs?  If so, your file would be in File.applicationDirectory, not in the applicationStorageDirectory.  

 

See This old post for info on mapping aliases to the app sandbox directories.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Problem With files concept

Should'nt it be:

var myFile:File = File.applicationStorageDirectory.resolvePath("sample.txt");

var fs:FileStream;
		
if(myFile.exists)
{
  trace("File Found");
  var fileStream:FileStream = new FileStream(); 
  fileStream.open(myFile, FileMode.READ);
  var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);  
  fileStream.close();
}
else
{
  trace("File Not Found");
}
		
		

 

 

Highlighted
Contributor
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

Re: Problem With files concept

Thank you sir,