首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

又一个有关问题,把dat中文本读出来了,想一行一行的读,高手给指点一下吧

2012-02-03 
又一个问题,把dat中文本读出来了,想一行一行的读,高手给指点一下吧把文本读出来了,可不知道怎么一行一行分

又一个问题,把dat中文本读出来了,想一行一行的读,高手给指点一下吧
把文本读出来了,可不知道怎么一行一行分开,程序如下:
  static   void   Main(string[]   args)
                {
                        byte[]   m_b   =   new   byte[10000];
                        char[]   m_c   =   new   char[10000];
                        try
                        {
                                FileStream   m_Fs   =   new   FileStream(@ "E:\HuaXia\source\6304-STMT30-20070515.dat ",   FileMode.Open);
                                m_Fs.Seek(0,SeekOrigin.Begin);
                                m_Fs.Read(m_b,0,10000);
                        }
                        catch(IOException   ex)
                        {
                                Console.WriteLine( "there   is   an   IOException ");
                                Console.WriteLine(ex.Message);
                                Console.ReadLine();
                                return;
                        }
                        System.Text.Encoding.GetEncoding( "GB2312 ");
                        Decoder   m_Dec   =   Encoding.Default.GetDecoder();
                        m_Dec.GetChars(m_b,0,m_b.Length,m_c,0);
                        Console.WriteLine( "read   from   file   succed! ");
                        Console.WriteLine(m_c);
                        Console.ReadLine();
                        return;
哪位仁兄给点指点吧,最好能在源程序上加点东本.在线等,马上给分

[解决办法]
要看你.dat文件中具体存放的是什么类型的数据,如果是文本,就直接用楼上的方法,如果你只是想读一千个字节换一行那估计没有太大的意义
[解决办法]
刚此那个写成写流了,应该是以下的这个
FileStream fs = new FileStream( "c:\\updatalog.txt ", FileMode.OpenOrCreate);
StreamReader sw = new StreamReader(fs);
sw.AutoFlush = true;
string data=sw.ReadLine();//这样读一行

------解决方案--------------------


你這文件是什麼編碼? unicode?還是 gb2312?
如果是 gb2312的話,你要指定流的編號格式的,因為默認是 unicode.
StreamReader sr = new StreamReader( "TestFile.txt ",System.Text.Encoding.ASCII);
sr.ReadLine();

热点排行