Android Question Read delimited text into table

GeoffT660

Active Member
Licensed User
Longtime User
I'm looking for the easiest most efficient way to read a text string or file into a device sqlLite table of the same structure as the server table. I have been able to receive either a text string or create a text file on the server and download it through httpUtils2 but am still unable to figure this out:
1) Save the downloaded file to a directory on the device
2) Parse the delimited text, whether streamed with Job.GetString or from the downloaded text file and append the records to a table. Please let me know how this can be done.
 

KMatle

Expert
Licensed User
Longtime User
Can you describe an example?

Generally: Files are files and data ist the content of a file or a table.

What I mean is:

Is it's a file then store it as a file. Only the index is stored in a table (with the path). If you need contents of the file it, then get the contents and store it in a table:

Get file from a folder on a server:

B4X:
Dim GetImage As HttpJob
          GetImage.Initialize("GetImage", Me)
          GetImage.Tag=filename
          GetImage.Download(ServerPath & FTPFolder & "/" & filename)

Save it to the device:

B4X:
Dim out As OutputStream
            out = File.OpenOutput(mypath & "/" & myFolder& "/", Job.Tag, False)
            File.Copy2(Job.GetInputStream,out)
            out.close

To read a file (to get the content) take a look to other examples in the forum.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Thanks, I was able to download and save the file in the desired location. I did not find any references to reading the comma delimited file (csv) and appending the rows to a table of the same format in the links. Do you have any information or know where I can find examples on that.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Something like this
B4X:
    Dim List1 As List
    List1 = File.ReadList(File.DirDefaultExternal, "1.txt")
    For i = 0 To List1.Size - 1
        Dim components() As String
        components = Regex.Split(",", List1.Get(i))
        For u = 0 To components.Length-1
            Log(components(u))
        Next
    Next
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Generally: Files are files and data ist the content of a file or a table.

@ KMatle,
remember to a add the above section to Murphy's Law #26 :)
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Dim List1 As List
List1 = File.ReadList(File.DirDefaultExternal, "1.txt")
For i = 0 To List1.Size - 1
Dim components() As String
components = Regex.Split(",", List1.Get(i))
For u = 0 To components.Length-1
Log(components(u))
Next
Next
Thanks. That did work fine I will start a new thread concerning appending to a SQL Lite Table.
 
Upvote 0
Top