本文介绍了编码从ANSI更改为UTF8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用我的代码打开一个txt文件,但是该文件采用ANSI(windows 1255)编码,并将其转换为UTF-8.我该怎么做?
I need to open a txt file in my code, but this file is in ANSI (windows 1255) encoding, and convert it to UTF-8. How can I do that?
推荐答案
System.IO.StreamReader reader =
new System.IO.StreamReader(fileName, System.Text.ASCIIEncoding.ASCII, false);
使用
System.IO.StreamWriter writer =
new System.IO.StreamWriter(fileName, false, System.Text.UTF8Encoding.UTF8);
这篇关于编码从ANSI更改为UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!