How to write Special characters in a file using vb.net

You may need to read / write some special symbols like these æ,Ø,å etc, into a text file. I had a similar situation where I needed to write some danish characters into the file.

Below is what I had used.

Dim encoding As Encoding
encoding = New UTF8Encoding()
Dim sw As StreamWriter
sw = New StreamWriter("filename.txt", False, encoding)
sw.WriteLine("vaøøibhav")
sw.WriteLine("vøøøøvvs")
sw.Close()

And if all fails, try this

Dim sw As New StreamWriter("filename.txt", False, System.Text.Encoding.Default)

admin