日期:2014-05-19  浏览次数:20719 次

读取文件时怎么解决中文的问题?
文本内容是中文的时候不能正常显示,应该怎么处理呢?
static   void   Main(string[]   args)
                {
                        string   path;
                        Console.WriteLine( "请输入完整文件名 ");
                        path   =   @ "D:\2.txt ";
                        try
                        {
                                if   (!File.Exists(path))
                                {
                                        Console.WriteLine( "file   is   not   exists ");
                                }
                                else
                                {
                                      FileStream   fs   =   File.OpenRead(path);

                                        byte[]   arr   =   new   byte[100];
                                        UTF8Encoding   utf8   =   new   UTF8Encoding(true);

                                        while   (fs.Read(arr,   0,   arr.Length)   >   0)
                                        {
                                                Console.WriteLine(utf8.GetString(arr));
                                        }
                                }
                        }
                        catch   (Exception   ex)
                        {
                                Console.WriteLine( "something   is   wrong:   "   +   ex.Me