Hi @StewartBW ,
- StreamWriter is optimized for writing text and handles encoding automatically. It is the best choice when you need to work with textual data, such as writing strings to a file.
- BinaryWriter is designed for writing primitive types in binary form. When you use
BinaryWriter.Write("Some String")
, it writes additional metadata (like the length of the string) and possibly other information, which is why you might see extra characters or spaces. It’s not suitable for pure text writing.
Using memoryStream As New MemoryStream()
memoryStream.Position = 0
Using streamReader As New StreamReader(memoryStream)
Using streamWriter As New StreamWriter("output.txt")
streamWriter.WriteLine("one single text line")
streamWriter.Write(streamReader.ReadToEnd())
End Using
End Using
End Using
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.