Original Author Paul Laughton, 2011
Page 225
De Re BASIC!
Files and Resources
Standard BASIC! loads its sample programs and the data files they need from the assets folder of the
Eclipse project. Android treats the assets folder like a file system. At startup, BASIC! simply copies the
entire assets/rfo-basic folder to the SD card.
Your application can use the assets folder, too. Most of the BASIC! file-handling commands look in the
SD card file system first. If the file does not exist on the SD card, your program compiled into an APK
looks in your projects's res folder, and finally in assets. Resources may be built into the APK in either the
res or assets folder, but res is not treated as a file system and has more restrictive naming rules. For
example, the name of a resource in res must not contain spaces or hyphens.
Both Byte.open and Text.open are able to open resources in your APK. However, Zip.open cannot open
resources; it looks only in the SD card file system. If you want to read a ZIP that is in assets, you must
first copy it from assets to the SD card. Then you can open the SD card file with Zip.Open.
File.Exists looks only for files on the SD card, but File.Type works with items in assets as well. You can
use them together to determine where an item is. The other File.* commands work with either files or
resources. Font.Load can load a resource if it does not find the font file on the SD card.
Files in assets are read-only. Your program can create and modify files on the SD card. It cannot create
or modify files in assets. If you want BASIC! to copy files from assets to the SD card, list them the
"load_file_names" tag of setup.xml as described above in "Advanced Customization with setup.xml".
File names in assets are case-sensitive. If your program looks for a file on the SD card, the name is not
case-sensitive: "meow.wav" and "Meow.WAV" are the same file. However, to find a file in assets, your
program must name the file exactly as you put it in assets. Audio.Load aft, "meow.wav" will not find
assets/rfo-cats/data/Meow.WAV.
For this practice APK, make the following changes:
1.
In the Package Explorer, expand Cats/assets/rfo-basic and its data and source folders.
2.
Right-click assets and select New -> Folder.
3.
In the Folder name: field, enter "rfo-cats/data".
4.
Click Finish.
5.
In the same way, create "rfo-cats/source".
6.
Drag assets/rfo-basic/data/meow.wav to assets/rfo-cats/data/.
7.
Drag assets/rfo-basic/source/my_program.bas to assets/rfo-cats/source/.
Note: the top folder in assets must exactly match what you put in the "app_path" item in
res/values/setup.xml. For this practice program, it is rfo-cats.
If you expand your new folders, your Package Explorer should look like this: