Text file does not save

I am working on an app that i need ASAP, and all of a sudden I could not save .txt files. I have spent hours trying to figure it out, but I cant. I have tried every way I can think of: Save with and with out slash, append with and without slash, giving it a straight up file name instead of joining strings together. Any thoughts?

1 Like

:sigh:

Please show your relevant blocks
Have you set permission for WRITE_EXTERNAL_STORAGE ?

Try this:

No need to ask for WRITE permission, the File component does it automatically.

No initial indication that the File component was being used ? :wink:

1 Like

Is there any other way in AI2 to save a text file without using an extension? :thinking:

The developer may have been trying to :slight_smile:

Me too!

Got quite confused last night, more clarity today.

The documentation on SaveFile block seems incorrect. My understanding as of now is :

  1. A / prefix does not store the file on the SD card. It is always in the Phone memory.

  2. It is not possible to increase the path by extra folders before the fileName supplied to the File component blocks..

  3. In Companion mode, the Windows path when not using the / is ...

Android/data/edu.mit.appinventor.aicompanion3/files/ and then fileName

When there is a / in front of the fileName, the path is as above, with an additional /data/ before the fileName. That means there is Android/data/... at the start of the path, and then another /data/ just before your fileName. The / you put in front of the fileName is not doubled up in the final full path to the file.

The confusing part of all this is that the documentation seems clear, but isn't what actually seems to happen.

One other confusing factor is that when I ran an app some weeks ago, it put the file in the highest level Phone folder. Now that isn't the case, or I've changed something. My theory is that the File component has been changed in the last few weeks.

My opinion is that where files get stored should not have the big path it has now, but no path or any length path is allowed; that the path should not have a particular version of aicompanion (3); that a leading / should allow storage to the SD card if preferred.

I haven't yet explored any differences in behaviour if the app is installed vs emulated vs companioned.

@Markeee Try this:

See also here: