trouble with file location

sarkis

Member
Licensed User
Longtime User
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
 

sarkis

Member
Licensed User
Longtime User
file location

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
 
Last edited:
Upvote 0

corwin42

Expert
Licensed User
Longtime User
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.

You do not need to create a directory for this.

If you mean the "Files" folder on the device then the location is "File.DirDefaultExternal".

This is the app folder on the SD-Card. Normal data dir for the app is File.DirInternal.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
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.
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
it is unclear

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
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
that link is the same shit as beginners guide.
It doesn't explain anything.
It is for the people who knows main ideas and forgot the syntax.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
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?
 
Last edited:
Upvote 0

sarkis

Member
Licensed User
Longtime User
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
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
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.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
The history.txt file is located in Files folder
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).
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
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?
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
1. all files must be included in DirAssets.
Yes, any files that are part of your app such as pictures, files, databases, etc must be included in the DirAssets folder.

2.All that locations are virtual, not physical folders.

No, the locations mentioned are physical folders on the device.

3.If application writes into a file, you need first to copy the file from DirAssets to an another location.

That is correct, you must copy them first.

Is this only for B4A or that is android platform restriction?

That's how it is, not really a restriction, is not particular to B4A or Android.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
without hijacking the thread can files placed in the objects/res/drawables be access 'in app'?
 
Upvote 0
Top