Android Tutorial File Path |Dir|Folder

I have filename.csv file contained two fields?
What folder do I have to copy my filename.csv file so I can access the csv file using loadcsv. eg.
Dim su As StringUtils
Dim Table As List
Table = su.LoadCSV(File.DirAssets, "filename.csv", ",")

I have copied the csv file to root dir of b4a folder, Files, bin,gen, res,src
and still get error message that csv file or folder not found.

What is the path for File.DirAssets?
msgbox(File.DirAssets,"") 'Display AssetsDir
I have made AssetsDir folder on root folder of .b4a file and copy the csv file there and still not working
Understand that folder are case sensitive

Can't find working sample in B4A HelpViwer V0.93.

Appreciate all the help I can get. Thanks.
I am a newie...:BangHead:
 

susu

Well-Known Member
Licensed User
Longtime User
1. On the bottom right of B4A IDE, click on Files button to add csv file into your apk file.

2. File.DirAssets:
The assets folder includes the files that were added with the file manager. These files are read-only. You can not create new files in this folder (which is actually located inside the apk file).

You can read this thread to know more about files.
http://www.b4x.com/forum/basic4android-getting-started-tutorials/6690-text-files.html
 

juncus

Member
Licensed User
Longtime User
Hi I have a similar problem I know about the various directory statements but in a development system where is the root folder. I'm trying to access a database but don't know where the system thinks it is if anywhere.

Do I for example have to write code to put it into a place as part of some installation routine or can it exist elsewhere. At this time I do not need to write to it.

I have referred to it as

SQL1.Initialize(File.DirAssets, "DbName.sqlite", True)

and have placed it in the Files list but it does not seem to be found.

In the tutorial we have this;

SQL1.Initialize(File.DirDefaultExternal, "test1.db", True)

But where is that in the file structure on disk and how does it get to the place referred to as File.DirDefaultExternal. This may be a newbie question but it seems to be one that no one states.

I'm sorry if I missed something but the text file tutorial tells us about the folders but not how to put things in them or where they come from on the local system.

Thanks
 

juncus

Member
Licensed User
Longtime User
Ok so I've discovered DBUtils.CopyDBFromAssets, but that did not help. So I've put in a check to see that the asset exists and that seem fine as the toastmsg is not shown. However I do get another error that I don't understand;

An error... in sub:
dbutils.Copy(File.DirAssets, FileName, TargetDir, FileName) java.io.IOException Continue?

The code is here:
If FirstTime Then
If File.Exists(File.DirAssets,"SomaRecorder.sqlite") Then
csStorageDir = DBUtils.CopyDBFromAssets("SomaRecorder.sqlite")
Else
ToastMessageShow("File doesnt exist",True)
End If
SQL1.Initialize(csStorageDir,"SomaRecorder.sqlite",False)
End If

Apologies but I'm still struggling with this android hardware.
Any ideas what I'm doing wrong?
 

margret

Well-Known Member
Licensed User
Longtime User
Ok so I've discovered DBUtils.CopyDBFromAssets, but that did not help. So I've put in a check to see that the asset exists and that seem fine as the toastmsg is not shown. However I do get another error that I don't understand;

An error... in sub:
dbutils.Copy(File.DirAssets, FileName, TargetDir, FileName) java.io.IOException Continue?

The code is here:
If FirstTime Then
If File.Exists(File.DirAssets,"SomaRecorder.sqlite") Then
csStorageDir = DBUtils.CopyDBFromAssets("SomaRecorder.sqlite")
Else
ToastMessageShow("File doesnt exist",True)
End If
SQL1.Initialize(csStorageDir,"SomaRecorder.sqlite",False)
End If

Apologies but I'm still struggling with this android hardware.
Any ideas what I'm doing wrong?

I don't really see a problem but try the code below:

B4X:
'Use This:
File.Copy(File.DirAssets, "SomaRecorder.sqlite", File.DirInternal, "SomaRecorder.sqlite")
SQL1.Initialize(File.DirInternal, "SomaRecorder.sqlite", True)

'In place of This:
csStorageDir = DBUtils.CopyDBFromAssets("SomaRecorder.sqlite")
SQL1.Initialize(csStorageDir,"SomaRecorder.sqlite",False)

Just as a test to see if the file copies with no error. What is csStorageDir equal to? That might be the issue.

Thanks,

Margret
 
Last edited:

juncus

Member
Licensed User
Longtime User
Thanks for that Margret, unfortunately that produces the same error for File.Copy line.

It looks rather like it cannot write to the destination. Do I have to initialise the destination?

I'm stumped for the moment. It might help to know that I could not get the SQL.Init.. to work with it in Assets; assuming I knew what I'm doing.

csStorageDir was set to File.DirDefaultExternal but when I changed to using DBUtils.CopyDBFromAssets that returns the location and was used to set csStorageDir [constant string storage directory]
 
Last edited:

juncus

Member
Licensed User
Longtime User
Thanks Erel interesting but I'm not sure what to make of the result. The file is only 1.12Mb in size and when renamed to a .jpg it works.

I'm somewhat puzzled how Android can be called an OS if it can't cope with a Db file of this size when Android systems have space of Gb's available.

One can hardly rely on a system to develop serious applications if 2Mb is too big.

How does one tell what type of file it will ignore? Is it just 'Oh that didn't work, we'll call it something different and see what happens';)

It concerns me when a stupid fault like this can take days of time to solve.

Thanks again, now to find why the next bit of code fails.
Juncus
 

agraham

Expert
Licensed User
Longtime User
I'm somewhat puzzled how Android can be called an OS if it can't cope with a Db file of this size when Android systems have space of Gb's available.
It's an embedded assets "expand a compressed data file" limitation, not an OS database size limitation. You aren't meant to pack multi-megabytes of data into your program's apk for access as an asset - although lots of programs do as it is a convenient way of getting the data on the device. Android compresses the asset files and re-expands them and the limitation is on the re-expansion. However the compression is not done for files that are known to be already compressed, like jpgs, so using such an extension on your data file avoids this limitation but obviously occupies more space in your apk and wastes memory on the device.
 

kickaha

Well-Known Member
Licensed User
Longtime User
It's an embedded assets "expand a compressed data file" limitation, not an OS database size limitation. You aren't meant to pack multi-megabytes of data into your program's apk for access as an asset - although lots of programs do as it is a convenient way of getting the data on the device. Android compresses the asset files and re-expands them and the limitation is on the re-expansion. However the compression is not done for files that are known to be already compressed, like jpgs, so using such an extension on your data file avoids this limitation but obviously occupies more space in your apk and wastes memory on the device.

Compressing the db with zip, and unzip it on the device with ABZipUnzip would save space.
 
Top