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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Contributor
satishmukku
Posts: 42
Registered: ‎08-30-2012
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.

Please use plain text.
Developer
UberschallSamsara
Posts: 685
Registered: ‎12-29-2010

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.

Please use plain text.
Developer
jtegen
Posts: 6,145
Registered: ‎10-27-2010
My Carrier: AT&T

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

 

 

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

Re: Problem With files concept

Thank you sir,
Please use plain text.