Android Question Including text files in my app

Brandsum

Well-Known Member
Licensed User
copy whatever file you want inside Files folder of your project and click on Sync button from the file manager window of B4A IDE
 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Thanks Brandsum. I tried that but it only creates a folder with the same name as the text file and with no content. This is the code I am trying to implement to open the named text file. I hope that I have pasted the code incorrectly. It's been a while. Tony

<code>
Sub Current_Click
shared = rp.GetSafeDirDefaultExternal("textcurrent.txt")
'SpinnerCurrent.AddAll(File.ReadList(rp.GetSafeDirRootExternal, "textcurrent .txt"))
SpinnerCurrent.AddAll(File.ReadList(shared, "textcurrent.txt"))
End Sub
</code>
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Thanks Brandsum. I tried that but it only creates a folder with the same name as the text file and with no content. This is the code I am trying to implement to open the named text file. I hope that I have pasted the code incorrectly. It's been a while. Tony

<code>
Sub Current_Click
shared = rp.GetSafeDirDefaultExternal("textcurrent.txt")
'SpinnerCurrent.AddAll(File.ReadList(rp.GetSafeDirRootExternal, "textcurrent .txt"))
SpinnerCurrent.AddAll(File.ReadList(shared, "textcurrent.txt"))
End Sub
</code>
You said that you want to include that file in your app. Then why are you calling external directory link?
B4X:
Sub Current_Click
 SpinnerCurrent.AddAll(File.ReadList(File.DirAssets, "textcurrent .txt"))
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png


rp.GetSafeDirDefaultExternal("textcurrent.txt")
Did you tried to read the Documentation of the methods you are using? GetSafeDirDefaultExternal

GetSafeDirDefaultExternal (SubFolder As String) As String
Returns the path to the app's default folder on the secondary storage device.
The path to File.DirInternal will be returned if there is no secondary storage available.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Just to help you. You can check the codes in https://www.b4x.com/android/forum/threads/b4xgoodies-check-app.110902/

Here I have text file (version.txt) in the app and also in starter service
SourceFolder = rp.GetSafeDirDefaultExternal("")

Then I check and copy the version.txt from my app to this external folder.

This may give you an idea for what you are trying to do.

Regards,

Anand
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You need to give more explanations on what exactly you want to do:
- Do you want to have text files just to read those from the project, without any modification ?
Then, use File.DirAssets and read them from there when you need them.
- If you need text files to read but you want to make modifications, but only for your project ?
Then use File.DirInternal. You need to check if these files don't exist in File.DirInternal, if no, you need to copy them from File.DirAssets to File.DirInternal.
- If you need text files accessible from outsides your application.
Then use rp.GetSafeDirDefaultExternal, and copy them if they don't exist.
 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Thanks Klaus. I want to read text files and modify them but only within my project. I have included these files in the Files Manager.
 
Upvote 0
Top