3
4

2 回答 2

2

If you are using ANSI, you can do it like this:

using (TextReader reader = new StreamReader(fs, System.Text.Encoding.Default))

However, that will only work if your current code page is correct for the file that you are reading. It probably will be, but for full portability you should determine the actual code page that you're using and use:

using (TextReader reader = new StreamReader(fs, new System.Text.Encoding(codePageNumber)))

where codePageNumber is the code page of the text file.

于 2013-02-05T13:44:59.903 回答
1

You can use the Mozilla Universal Charset Detector, a .NET port of which is available here to determine the encoding for a file pretty reliably. That will let you then open most files with the correct encoding with very little effort on your part.

于 2013-02-05T13:37:17.350 回答