To read a .txt File of a particular Encoding type in C# [duplicate]
Possible Duplicate:
How can I detect the encoding/codepage of a text file
I have to read a (text) .txt file.But I don't know its encoding type.The encoding type may be
Encoding.ANSI
or
Encoding.Unicode
So my question is 'How can we know and read that a specific file is of particu开发者_开发问答lar encoding type?'
try this
StreamReader sr = new StreamReader(@"C:\CreateAsciiFile.txt",true);
string LineText= sr.ReadLine();
System.Text.Encoding enc = sr.CurrentEncoding;
Check this answer it might help you : http://www.eggheadcafe.com/community/aspnet/2/10077748/get-file-encoding.aspx
have look to this also : Encoding Methods
In general - you can't. The StreamReader constructor has an builtin heuristic to guess the encoding if you don't provide it, which may be good enough for you, but that is not a 100% solution
Read this article of Joel Spolsky
http://www.joelonsoftware.com/articles/Unicode.html
to get more insights.
精彩评论