Android Question Write a new string in continuation of the previous .txt file

Sorry for simple question and poor English.
Some strings are sending to my device with serial (usb serial) and I have to save them in a text (.txt) file.
But when I use
B4X:
File.WriteString(File.DirInternal, "Logs.txt", NewData )

previous string is deleted and a new text file with the last received string is generated.
How can I add NewData in continuation of the previous text?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Two options:
1.
B4X:
File.WriteString(File.DirInternal, "Logs.txt", File.ReadString(File.DirInternal, "Logs.txt") & NewData )

2.
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "Logs.txt", True) 'Append = True
Dim b() As Byte = NewData.GetBytes("utf8")
out.Write(b, 0, b.Length)
out.Close

2.1 Same as above but with TextWriter.
 
Upvote 0
Top