Can not write text file

Look at my blocks:

I only read from //text.txt because I want to get the text from the text.txt file (stored in the assets).
When I got that text, I save it in the new text.txt file in the Private dir.

(Btw, no need to add " + def". This was only an example.)

I can understand well the above blocks, but when I run the app the second time I read from // original file without changes. Why not so ?

Try this:

grafik

This way the text is only read for the first run of the app.
Then the new text.txt file is created in the Private dir and the text may be changed.
When the app is restarted or the screen is reopened the block (btReadText) will never be executed because if(TinyDB.GetValue -> firstRun) = false.

It's OK, but can you answer to my post 23 ? what do you think about my blocks ?

Please explain exactly what the goal is (what should be achieved):

  1. Read the text file (appunti.txt) from the assets (at Screen.Initialize ?).
  2. Save the text in the new file (appunti.txt) in the Private dir.
  3. ...
  4. ...

my goal is to avoid error on first run

  1. Read the text file (appunti.txt) from Private dir
  2. if not exist (screen error) save the text in the new file (appunti.txt) in the Private dir.
    then add text and save

Which text?
Where does the text come from since the text file does not exist on the first run?

textbox text to create file

So this textbox is not empty at the first run (at Screen.Initialize)?
Post a test aia to shorten this conversation.

Try this: copyTextToPrivateDir.aia (34.8 KB)

your project runs well, but i think this attached too
APPUNTI.aia (13.3 KB)

@Anke, thanks for all suggestions, the best solution for me is this

Okay, if you feel that is the best solution, you should close this topic by pressing the solution button in that post.

I'm beginner, I'm waiting for comments, it's the best for me, but maybe there are some bugs I can not see.

So actually what functions do you want for your app.

And also see this :
http://ai2.appinventor.mit.edu/reference/components/storage.html#File

read/write a textfile

I see you want to create a Note App but use the functions of the text file right?

You are right, but i just want to know if my approach is correct

Try my new Note App project, it might be very helpful :
NoteApp.aia (6.1 KB)

Note :

  • This App saves data using Component (File).
  • If You Get Bugs Or Errors, please let me know.
  • If this project is successful without any bugs or errors, I will make a topic for this

Regards,
Salman Dev

Thank you for your app, but I would like to know if my approach is correct to read, edit and save a text file. I want to learn and not copy others' code