B4J Question WriteLine function

PatrikCavina

Active Member
Licensed User
I tried to write more lines in .txt file with function WriteLine, but the result is a txt file with only one line.
This is an example of what i want to do:
B4X:
    Dim f As TextWriter
    f.Initialize(File.OpenOutput("C:\Users\user01\Desktop","a.txt",True))
    f.WriteLine("1")
    f.WriteLine("2")
    f.WriteLine("3")
    f.Close

I tried also:
B4X:
Sub AppStart (Form1 As Form, Args() As String)

    Dim st() As String = Array As String("1","2","3")
    For i = 0 To st.Length-1
   
        Write(st(i))
   
    Next
   
End Sub

Sub Write(tx As String)

    Dim f As TextWriter
    f.Initialize(File.OpenOutput("C:\Users\user01\Desktop","a.txt",True))
    f.WriteLine(tx)
    f.Close

End Sub

But the result is the same, all strings are written in only one line
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Add newline code.

B4X:
Dim f As TextWriter
    f.Initialize(File.OpenOutput("C:\Users\user01\Desktop","a.txt",True))
    f.WriteLine("1" & Chr(13))
    f.WriteLine("2" & Chr(13))
    f.WriteLine("3" & Chr(13))
    f.Close
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Also,

f.WriteLine("3" & CRLF) 'which is the shortcut for Chr(13)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
It also depends on which editor you use to read the file.
Using Notepad++ you will get separate lines, as that will take the LF at the end of the line as if it were CRLF.
Reading the file back in with f.ReadLine will read them as separate lines too.
 
Upvote 0
Top