09-04-2012 02:53 AM
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);
Solved! Go to Solution.
09-04-2012 03:04 AM
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);
09-04-2012 10:31 AM - edited 09-04-2012 10:32 AM
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);
}
09-08-2012 08:56 AM
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.
09-08-2012 05:16 PM
09-10-2012 02:32 AM
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
09-10-2012 02:42 AM
09-10-2012 08:14 AM