Read and write files from our apps


Ava Rashidi

Hi David,

I wish you a very sweet and prosperous New Year.

I want read and write in file, I'm doing these steps:

for write:

FileWrite "Other.txt" "[WriteTextarea.Value]" "ErrorCallback" "SuccessCallback"

fore read:

FileRead "dataDirectory" "Other.txt" "ErrorCallback" "SuccessCallback"

and add 2 functions

ErrorCallback:

Alert "Error" "Read or write error: [Error]"

SuccessCallback:

SetVar "[ReadTextarea.Value]" "[Text]" "String"

and also add text file to the file manager.

But my program does not work!

-Where is my mistake?

-How does [text] argument work in SuccessCallback function?

-What is the difference between applicationDirectory and dataDirectory in FileRead function?

Thanks

DecSoft

Hello Ava,

Thanks for your kindly words, and, Happy New Year to you too! :-) Now I will try to reply to your questions one by one:

Where is my mistake?

Maybe you are trying to run the program without firstly compile it with Apache Cordova? First of all, please, try the "Files" app sample: I do it right now and works like a charm in Android. Remember that the "Files" sample must be compiled with Apache Cordova in order to properly work.

How does [text] argument work in SuccessCallback function?

You can take a look at the actions' documentation. In the case of the Files sample we use an app's "SuccessCallback" function for both write and read operations. In the first case, we do not receive any function's argument, so the "SuccessCallback" is just executed indicating that the write operation end successfully.

The "Files" app sample also uses the "SuccessCallback" for the read operation. In this case, that app's function receives an argument, with the text that we read from the file. This text come to the function as a regular / normal function's argument.

-What is the difference between applicationDirectory and dataDirectory in FileRead function?

I want to refer to the official Apache Cordova documentation. There you can see what "dataDirectory" and "applicationDirectory" is (certainly this is not well refered in the AB help).

I also point you to the official documentation for the Files plugin of Apache Cordova, because, certainly there you can be informed about other possible uses of that plugin. DecSoft's App Builder provides easy to use actions to read and write text files, but, you know that we can go ahead if needed, directly using the appropriate Javascript, in this case the Javascript provided by the Files plugin of Apache Cordova.

Remember also that we can use the app's local storage (with the "GetOption" and "SetOption" actions) to store more or less small pieces of text in the client side. And rememeber also that we can always use an app's server, to, by made the appropriate HTTP calls, we can deal with files stored in the app's server, who can be useful, for example, since this files are not removed even if an app is uninstalled.

Please, Ava, go ahead if you have any further questions.



Ava Rashidi

Hi David,

My problem was not to select the files plugin!

Your good and complete description helped me and my problem has been resolved.

thank you very much.

DecSoft

Hello Ava,

Hi David,

My problem was not to select the files plugin!

Your good and complete description helped me and my problem has been resolved.

thank you very much.

You're welcome! :-)


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.