c# console.write_filestream.readbyte_从文件中读取并显示在控制台

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;//arraylist派生于array类
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
       //学习while
      public static void Main(string[] args)
      {
          int i;
          FileStream fin;
          //if (args.Length != 1)
          //{
          //    Console.WriteLine("usage:showfile file");
          //    return;
          //}

          //打开文件
          try
          {
              fin = new FileStream(@"c:\testphone.txt",FileMode.Open);

          }
          catch(IOException exc)
          {
              Console.WriteLine("不能打开文件");
              return;
          }

          //打开文件后直到文件末尾
          //读取文件中的内容
          do
          {
              try
              {
                  i = fin.ReadByte();
              }
              catch(IOException exc)
              {
                  Console.WriteLine("读取文件出错");
                  Console.WriteLine(exc.Message);
                  break;//直接退出do循环,不再读取文件
              }
              if (i != -1)
                  //console.write((char)i);//在控制台中输出自文件流中读取的字符
                  Console.Write((char)i);
                 
          } while (i!= -1);//i=-1表示到文件末尾
          Console.ReadKey();
      }
    }
   
}

请使用浏览器的分享功能分享到微信等