Begginers questions about Files

glook

Member
Licensed User
Longtime User
I'm probably going to feel really stupid asking this, but --


Q1. How can I open a file on the SD card?

I have a file in a directory on the emulator's SD card - /sdcard/pbdb/PB.dpbm
In this case it is a database file, so try to open it :
B4X:
con.Initialize(File.DirRootExternal, "pbdb/PB.dpbm",False)
I also tried "DirDefaultExternal" and adding "/sdcard/" to the path, but it always fails to open. (I checked it is really there and correct name).

It also fails if I try to create a new test file (on sdcard).


Q2. How do I copy an existing file to the "DirInternal" ? Where does it go?

I created a new test DB file that works, but I can't see it anywhere. I thought it would be under the /data directory, but it appears empty.

Geoff.
 

glook

Member
Licensed User
Longtime User
Ah - it wasn't obvious what was happening with the SD card. Long-term, it will be needed as I use large database files.

Q2 - I probably didn't explain this very well. I was simply attempting to copy an existing database file from my PC to the internal storage of the emulator. I assume this can be done with "adb push", but what is the destination direcory for DirInternal? Or should I be using another directory?

I had already made a new database using File.DirInternal, but I cannot see it anywhere in the file system (using AndExplorer). If I found this test file, I could perhaps use that location for adb push.

Hope that makes sense? I'm fairly OK with Unix/Linux filesytems but the Android layout is still a bit of a mystery.
 
Upvote 0

mtw

Member
Licensed User
Longtime User
glook use "adb shell" at a command prompt then you can use the unix ls command to list files.

btw: I did a File.DirInternal it was /data/data/com.Tester/files but since Tester was the name of the app, it wont be on yours, but at least you know where the file will be.
 
Last edited:
Upvote 0

glook

Member
Licensed User
Longtime User
The fog is starting to lift!!

Thanks to both for the tips

I was confused by AndExplorer showing the /data directory as being empty - there must be some sort of restriction or hidden option, while ls reveals all.

Still a lot to read and learn - I can see that adb is going to become a good friend!
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Is it possible to include a directory with files in the file manager, to be part as the apk (with whatever is in the directory) ?
As an example for the need - a directory of maps for a GPS application.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
The specific maps folder is much bigger, I guess it will have to be installed directly to the sdcard by memory reader, but I think there will be other cases, like a set of small wav files or text files etc. that will be less then 5 Mb
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The specific maps folder is much bigger, I guess it will have to be installed directly to the sdcard by memory reader, but I think there will be other cases, like a set of small wav files or text files etc. that will be less then 5 Mb
You can add those with the file manager (Files tab).

Where is "send to back" and "bring to front" ?
In the designer - Tools - Bring to front.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I have a file test.txt in my hard drive. I want my Android app to read the contents of the file and populate a list on run time. I read the tutorial and learnt all the file read write commands. My question is in which folder on my hard drive should I put test.txt to be accessible with File.ReadList(File.DirInternal,"test.txt"), to try the app on emulator?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
But if I declare the file as an asset, I cannot write to it, right? I need to update the file with new content when I load the app.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
So it is not possible to maintain a file like for example a settings.ini in the internal memory, like we store the same file in the app folder on Windows to read and write settings?
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
For a .ini type file use the Map thingy, it works great,
For memory save it to

File.DirDefaultExternal
for the SD card
or
File.DirInternal
for the phones memory
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
Inman, I should have said

YES, you can save a file to the SD card or the internal memory

Map is:A collection that holds pairs of keys and values
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Thanks LittleEddie. That does solve the ini issue.

But what about plain text file? I have a list of data (one item per line). I need to bundle this list with my app and the app will read the data from the file and display it in a listview. After that, the app will connect to a website and download more data into this text file. I don't want to put this file on memory card and give access to the user. It will be safer in the internal memory.

Can this be done?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…