请问怎么将一个文件读到一个字符串数组里面啊?

解决方案 »

  1.   

    // string input = "";
    // string html = "";
    /// do
    // {
    // input = sr.ReadLine();
    // if(input != "")
    // {
    // html = html + input + "\r\n";
    // }
    // }while(sr.Peek()!=-1);
      

  2.   

    // html = html + input + "\r\n";这里改为 input 赋值给数组
      

  3.   

    System.IO.StreamReader sr=new System.IO.StreamReader("test.txt");
    string str1=sr.ReadToEnd();
    sr.Close();
    string[] strArr=str1.Split('\n');
      

  4.   

    string[] Item;        //read file
            public Array ReadFile(string filePath)
            {
                int i = 0;
                int line;
                StreamReader sr;
                sr = File.OpenText(filePath);
                string s = sr.ReadLine();
                while (s != null)
                {
                    line++;
                    s = sr.ReadLine();
                }
                Item = new string[line];
                s = sr.ReadLine();
                while (s != null)
                {
                    Item[i] = s;
                    s = sr.ReadLine();
                    i++;
                }
            }
    我这个写的对吗?