2017년 1월 2일 월요일

File component issue


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 ?
--
All files in the assets folder are read-only and you won't be able to write to that folder.

--
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         



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.

--
I believe the assets folder is-not writable and as result the documentation has to be updated to reflect this.

--
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...

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

--
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.
file.aia

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

--

댓글 없음:

댓글 쓰기