Android Question Read delimited text into table

Discussion in 'Android Questions' started by GeoffT660, Jan 28, 2015.

  1. GeoffT660

    GeoffT660 Active Member Licensed 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.
     
  2. KMatle

    KMatle Expert Licensed 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:

    Code:
    Dim GetImage As HttpJob
              GetImage.Initialize(
    "GetImage", Me)
              GetImage.Tag=filename
              GetImage.Download(ServerPath & FTPFolder & 
    "/" & filename)
    Save it to the device:

    Code:
    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.
     
    Beja likes this.
  3. GeoffT660

    GeoffT660 Active Member Licensed 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.
     
  4. DonManfred

    DonManfred Expert Licensed User

    Something like this
    Code:
    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
     
    Beja likes this.
  5. Beja

    Beja Expert Licensed User

    @ KMatle,
    remember to a add the above section to Murphy's Law #26 :)
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You can use StringUtils.LoadCSV to read CSV files.
     
  7. GeoffT660

    GeoffT660 Active Member Licensed User

    Thanks. That did work fine I will start a new thread concerning appending to a SQL Lite Table.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Note that this code will fail if there are fields with commas. StringUtils.LoadCSV will work correctly.
     
    GeoffT660 and DonManfred like this.
  9. GeoffT660

    GeoffT660 Active Member Licensed User

    Thanks. I'll try LoadCSV.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice