i want to append text to "file.txt" in each new line. But its joining text when i use "write" instead of "writeline" like this "TEXTTEXT"
The problem is "writeline" leaves characters end of the text as if you press enter like space. you just see them when you open it with wordpad if you select the text.
And if you get read this lines but StreamReader and assign a variable this chars will be added to end of the text and you get error.
i cant use "Write" beacause of it is joining text if append new text

i am wating for your help. How can i get it write to new line using "Write" or solve end of chars in "WriteLine" command?

Dim fs As IO.FileStream = New IO.FileStream("file.txt", IO.FileMode.Append)
            Dim sw As IO.StreamWriter = New IO.StreamWriter(fs)
            sw.Write("TEXT",Trim)
             sw.Close()

hello
use this

        Dim fs As IO.FileStream = New IO.FileStream("d:\a.txt", IO.FileMode.Append)
        Dim sw As IO.StreamWriter = New IO.StreamWriter(fs)
        sw.Write("TEXT" & vbCrLf)
        sw.Close()

Regards

i am working on it. But i still have same problem "& vbCrLf" is also adding "two more character end of the line"
you can test it

    Dim fs2 As IO.FileStream = New IO.FileStream("test.dat", IO.FileMode.Create)
    Dim sw2 As IO.StreamWriter = New IO.StreamWriter(fs2)
    sw2.Write("TEXT" & vbCrLf)

    sw2.Close()

    Dim address As String
    address = "test.dat"
    Dim client As WebClient = New WebClient()
    Dim url As String = client.DownloadString(address)
    MsgBox(url.Length)

url.Length=6 in this case
it will be 4 if you change it as sw2.Write("TEXT"). And you cant write it second line

i am gonna be happy if you help me to solve this

Edited 4 Years Ago by ulasoc

i mean if you create a text file manually and get it write to antother text file line by line. Second file size would be big then first

i love to help you .but please can you little bit explain what you want ,
if i am wrong please make me correct
you want to create a file and then you want to write it ?

yes i want to write a file reading from another.
Source File is a text file created manually. (for example notepad) its a list includes text lines

LINE
LNE2
LNE3

Dim sn As String

    Dim fs As IO.FileStream = New IO.FileStream("source.dat", IO.FileMode.Open)
    Dim sr As IO.StreamReader = New IO.StreamReader(fs,System.Text.Encoding.GetEncoding(28599))



    Dim fs22 As IO.FileStream = New IO.FileStream("target.txt", IO.FileMode.Create)
    Dim sw22 As IO.StreamWriter = New IO.StreamWriter(fs22, System.Text.Encoding.GetEncoding(28599))

    '
            While sr.Peek <> -1


        sn = sr.ReadLine

        sw22.Write(sn.ToString.Trim & vbCrLf)

    End While


    sw22.Close()
     sr.Close()

target.txt is being big then source.txt
i like to edit first file and add new lines creating second file.
But i am getting error if i get read target.txt but streamreader. i cant create same even i get it read line by line write to another

Edited 4 Years Ago by ulasoc

This article has been dead for over six months. Start a new discussion instead.