Problem with TextoutputStream

I have open my file without problems and change the data i want.
The lines is stored in array like the screenshot below.
The problem is when i save the new file is a mess !!
Can someone point me where or what i do wrong?
The code to read my file.

Dim ThenewLine as string Dim ErrorText As Text Try Dim input As TextInputStream input = TextInputStream.Open(TargetFile, TextEncoding.UTF8) Dim testArray(-1) as string Dim line as string While Not input.EOF TotalLines = TotalLines + 1 Line = input.ReadLine ThenewLine=ReadTheLine(line) NewFile.Append ThenewLine Wend input.Close break //to see the results Catch e As IOException ErrorText = "File IO Error: " + e.Reason End Try
and this is to save the file

Dim NewLine As text Dim output As TextOutputStream Try For i As Integer = 0 To NewFile.Ubound NewLine = NewFile(i).ToText output = TextOutputStream.Append(TargetFile, (Xojo.Core.TextEncoding.UTF8)) output.Write NewLine Next output.Close Catch e As IOException MsgBox "Error" End Try

The first screenshot is from Array and is perfect like the original file
Second screenshot is the comparison of the 2 files (Left is Original file <>Right the new saved file)
http://i.imgur.com/vQPyinv.png
http://i.imgur.com/b7Hju95.png

Thank you

WRITE does not add an ENDOFLINE

WRITELINE does

[quote=269872:@Dave S]WRITE does not add an ENDOFLINE

WRITELINE does[/quote]
@Dave S I have test it with both the same results

So add a WriteLine that adds an EndOfLine and see if that helps?

Give me a min to post the new screenshots…
I get the end of line but still is a mess :slight_smile:
http://i.imgur.com/BJuEltL.png
http://i.imgur.com/l5k9RBN.png
Both screenshots is with writelline,the problem if you see is the empty lines that do NOT exist in the array…
The comparison of the 2 files is.
Original file 50mb
Saved file 25mb

try this

    Dim input As TextInputStream
    input = TextInputStream.Open(TargetFile, TextEncoding.UTF8)
    Dim testArray(-1) as string
    Dim line as string
    dim s as String = input.readall
    input.Close
    s=replaceLineEndings(s,endofline.unix)
    NewFile=split(s,endofline.unix)
    totalLines=newFile.ubound
    break //to see the results
  Catch e As IOException
    ErrorText = "File IO Error: " + e.Reason
  End Try
 Dim output As TextOutputStream 
    Try
    dim s as string=join(newfile,endofline.unix)
            output = TextOutputStream.Append(TargetFile, (Xojo.Core.TextEncoding.UTF8))
      output.Write NewLine   
    output.Close
  Catch e As IOException
    MsgBox "Error"
  End Try

Move Append OUTSIDE the loop. You’re opening the file over and over without closing it.

Thank you @Dave S @Tim Hare @Tim Parnell ,as Tim say was the append.
Thank you again.