Skip to first unread message

mnja...@gmail.com

unread,
May 29, 2014, 7:43:33 AM5/29/14
to mitappinv...@googlegroups.com
Hi

I am using the File component to read a text asset file. I have no problem in reading the file with "Call File1.ReadFrom fileName" block. However when I use the "Call File1.AppendToFile text fileName" block, an error "Error 2016 : cannot write asset file at //FileDB.txt". FileDB.txt is my text asset file.

Any suggestions to fix the problem ?

Thanks & regards
M.N. Jayaram

M. Hossein Amerkashi

unread,
May 29, 2014, 7:46:42 AM5/29/14
to mitappinv...@googlegroups.com
All files in the assets folder are read-only and you won't be able to write to that folder.

-Hossein.

Taifun

unread,
May 29, 2014, 9:26:20 AM5/29/14
to mitappinv...@googlegroups.com
All files in the assets folder are read-only and you won't be able to write to that folder.
according the documentation http://ai2.appinventor.mit.edu/reference/components/storage.html#File this is possible
you might want to provide a screenshot of your relevant blocks
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         



AppendToFile(text text, text fileName)
Appends text to the end of a file storage, creating the file if it does not exist. See the help text under SaveFile for information about where files are written.

SaveFile(text text, text fileName)
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard. For example writing to /myFile.txt will write the file to /sdcard/myFile.txt. If the filename does not start with a slash, it will be written in the programs private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists. If you want to add content to a file use the append block.

M. Hossein Amerkashi

unread,
May 29, 2014, 10:19:54 AM5/29/14
to mitappinv...@googlegroups.com
I believe the assets folder is-not writable and as result the documentation has to be updated to reflect this.

-Hossein.

Taifun

unread,
May 29, 2014, 10:37:49 AM5/29/14
to
some more testing is required...
meanwhile I think, you only can read a text file from the assets as Hossein said.
If you want to append, you have to save first into the programs private data directory (which is different from the assets directory) and then append there...
Taifun

M. Hossein Amerkashi

unread,
May 29, 2014, 10:54:27 AM5/29/14
to mitappinv...@googlegroups.com
Taifun,

Your example does not write to assets folder. To reference the assets folder you have to prefix with double slashes (//).

-Hossein.

Taifun

unread,
May 29, 2014, 11:08:54 AM5/29/14
to mitappinv...@googlegroups.com
Hossein is correct, you can't write to assets folder.
If you want to append, you have to save first into the programs private data directory (which is different from the assets directory) and then append there...
screenshot and example project attached.
Taifun


file.aia

Andras Pulai

unread,
Oct 24, 2014, 1:55:12 AM10/24/14
to mitappinv...@googlegroups.com
Hi! 

This is very similar to what I wrote. Thanks for your help, I will test it! 

Andras
Reply all
Reply to author
Forward
0 new messages