Write UTF8 encoded string to a file
Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\MyTest.txt"
Dim fi As FileInfo = New FileInfo(path)
If fi.Exists() Then
fi.Delete()
End If
Dim fs As FileStream = fi.Create()
Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")
fs.Write(info, 0, info.Length)
fs.Close()
Dim sr As StreamReader = fi.OpenText()
Do While sr.Peek() >= 0
Console.WriteLine(sr.ReadLine())
Loop
sr.Close()
End Sub
End Class
Related examples in the same category