Hi all,
My application needs in a small external txt file for read and write.
File.ReadList and File.WriteList methods are ok
but I have troubled with file location.
Where should I store my txt file (it was already created out of B4A)
when I am using
1.File.DirInternal / File.DirInternalCache
2. File.DirRootExternal
3. File.DirDefaultExternal
respectively ?
My file currently located in Files folder.
And second question
Do I need to create appropriate directory on phone and if yes how to do that?
Thanks for replying
I tried .It doesn't work with
File not found exception .
When i created an application B4A created Files and Objects folders.
I mean that folder.
And explain how my file should be located in real phone?
Thanks for answer
Where should I store my txt file (it was already created out of B4A)
[...]
Do I need to create appropriate directory on phone and if yes how to do that?
Thanks for replying
If I understand correctly you have a file that is externally created and you want to put into the apk but you need to write it, too?
You have to add it to the Files folder of your project.
On first start of you app you should copy the file to File.DirInternal. That is the normal place for storing app data.
Then use the file on File.DirInternal.
Ok, in that case you can copy the file to the device like this:
B4X:
If File.Exists(File.DirDefaultExternal, "MyFile.txt") = False Then
File.Copy(File.DirAssets, "MyFile.txt", File.DirDefaultExternal, "MyFile.txt")
End If
Or any other folder, like File.DirInternal if you wish.
You are write.
I need an external file for read and write.
But I don't understand
"On first start of you app you should copy the file to File.DirInternal."
what is that "File.DirInternal" ,where is that ?
Copy from where to where?
Please explain
Ok, calm down, I posted an example and you still asked, I sent you a link to the docs, you didn't like it, so, what's your problem? what don't you understand?
I need to understand what are all that locations.
1.File.DirInternal / File.DirInternalCache
2. File.DirRootExternal
3. File.DirDefaultExternal
Is these real folders ,where they located in my computer where they are on the phone?
First I want to work my application on emulator.
The history.txt file is located in Files folder
here is the code
Dim History As List
History=File.ReadList(File.DirDefaultExternal, "history.txt")
It failed with no file found exception.
thanks
Well, those are FOLDERS ON THE DEVICE not your computer or the emulator, if you read the "beginners" docs it says it right there: "Android stores files in several different locations"
Your code:
B4X:
Dim History As List
History=File.ReadList(File.DirDefaultExternal, "history.txt")
Doesn't work because you MUST copy the file from the Assets directory to the device first, if you look at the sample code I posted before it explains how is done.
If you want yo know where the ASSETS folder is, then again, read the link I posted it explains it clearly.
That is not how you add files to the 'Files' folder.
In the IDE in the Files tab, you need to 'Add' files from here.
i.e. you add Files to the Assets folder from the IDE and NOT by copying into Files.(unless you set it to read-only).
what I have understand.
1. all files must be included in DirAssets.
2.All that locations are virtual, not physical folders.
3.If application writes into a file , you need first to copy the file from DirAssets to an another location.
If these are correct I don't have any questions so far.
I never mind that to write to the file you need first make a writable copy .
It is strange .
Is this only for B4A or that is android platform restriction?