B4J Question Save data in a txt-file

Orejana

Member
I'm quite new to coding and I have never worked with saving stuff into an external file before.
I want to save multiple things to one line, e.g. temperature and date, "32", "08/06/18" or similar to that. I can't seem to figure out which text file method to use, can someone help me please? Thanks a lot! :)
 

supriono

Member
Licensed User
Longtime User
maybe like this
B4X:
temp="32"
time="08/06/18"
save("log.Text",temp&","&time)

Sub save(namefile As String,value As String)
    File.WriteString(File.DirTemp,namefile,value)
End Sub
 
Upvote 0

Orejana

Member
maybe like this
B4X:
temp="32"
time="08/06/18"
save("log.Text",temp&","&time)

Sub save(namefile As String,value As String)
    File.WriteString(File.DirTemp,namefile,value)
End Sub

Thanks for your replies!
I tried it like this, but didn't know how to retrieve this data separately lateron. Any tipps for that?
 
Upvote 0

supriono

Member
Licensed User
Longtime User
Thanks for your replies!
I tried it like this, but didn't know how to retrieve this data separately lateron. Any tipps for that?
B4X:
open("log.txt")
Sub open(namefile As String)
    Dim x As String
    x=File.ReadString(File.DirTemp,namefile)
    temp=x.SubString2(0,1)
    time=x.SubString(3)
End Sub
 
Upvote 0

Orejana

Member
Why does it need to be a text file?

It actually doesn't, thanks for that tip :-D
Saving works fine now, but if I want to log the loaded CSV, I only get: (ArrayList) [[Ljava.lang.String;@408efbe8, [Ljava.lang.String;@5ad11920, [Ljava.lang.String;@78285dd6]
What did I do wrong?
B4X:
    table2 = su.LoadCSV(File.DirApp, "2.csv", ",")
   Log(table2)
 
Upvote 0
Top