如果逐行读取文本中的字符  如果到了最后一行 提示

解决方案 »

  1.   

    用while循环呀,到了未尾就会退出循环,再让给个提示就行了。
      

  2.   

    using System;
    using System.IO;public class TextFromFile 
    {
        private const string FILE_NAME = "MyFile.txt";    public static void Main(String[] args) 
        {
            if (!File.Exists(FILE_NAME)) 
            {
                Console.WriteLine("{0} does not exist.", FILE_NAME);
                return;
            }
            using (StreamReader sr = File.OpenText(FILE_NAME))
            {
                String input;
                while ((input=sr.ReadLine())!=null) 
                {
                    Console.WriteLine(input);
                }
                Console.WriteLine ("The end of the stream has been reached.");
                sr.Close();
            }
        }
    }
      

  3.   

    using System;
    using System.IO;public class TextFromFile 
    {
        private const string FILE_NAME = "MyFile.txt";    public static void Main(String[] args) 
        {
            if (!File.Exists(FILE_NAME)) 
            {
                Console.WriteLine("{0} does not exist.", FILE_NAME);
                return;
            }
            using (StreamReader sr = File.OpenText(FILE_NAME))
            {
                String input;
                while ((input=sr.ReadLine())!=null) 
                {
                    Console.WriteLine(input);
                    Console.ReadLine();
                }
                Console.WriteLine ("The end of the stream has been reached.");
                sr.Close();
            }
        }
    }
      

  4.   

    wuyi8808 的写法好像不错哦
      

  5.   

    StreamReader sr = new StreamReader();
    sr.EndOfStream;这是返回流是否读到末端,可以配合readline()使用
      

  6.   


    System.IO.File.ReadAllLines("path");