I have a txt file whose encoding is UTF8 and the content is a mixed English and Chinese character plus a simplified Chinese character string I want to convert the encoding to ANSI format for use by other programs. But I use StreamReader and StreamWriter for encoding conversion Simplified Chinese part of the new txt file turned out is garbled
Strangely, when I use the built-in notepad of windows to save a new file and change the UTF8 encoding to ANSI encoding, the file content is displayed as a mixture of simplified Chinese and English.
How can I modify it?
The code used is as follows:
try
{
System.IO.StreamReader streamReader = new StreamReader(tPath, Encoding.GetEncoding("utf-8"));
string str = "";
str = streamReader.ReadToEnd();
FileStream fs = new FileStream(tPath2, FileMode.Create);
using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
{
sw.Write(str);
sw.Flush();
sw.Close();
sw.Dispose();
}
}
catch (IOException ex)
{
string msg = ex.Message.ToString();
MessageBox.Show(msg);
}