f盘里面有一个 abc.txt的文件 我想用C#打开这个文件把里面的 内容读到一个字符串数组中如何实现 谢谢!!! 只有20分了全送了

解决方案 »

  1.   

    我有VB,NET的,你只要稍微改下就可以了
    主要是思路
     Dim myreader As IO.StreamReader = New IO.StreamReader(TxtBx_filepath.Text, System.Text.Encoding.Default)
            Dim tr(26) As String
            Dim rws As String
            Dim chararray() As Char = {", "}
            rws = myreader.ReadLine()
            While Not myreader.EndOfStream
                Try
                    tr = rws.Split(chararray)
                    daysss = CleanInput(tr(5))
                    If Val(CleanInput(tr(11))) > 0 And tr(8).Length > 9 And tr(6) = (Chr(34) & StrConv(Space(4), VbStrConv.Wide) & Chr(34)) Then
                        Dim derow As DataRow = filtable.NewRow()
                        derow(0) = CleanInput(tr(7))
                        derow(1) = CleanInputs(tr(11))
                        derow(2) = CleanInputs(tr(0))
                        derow(3) = CleanInput(tr(5))
                        filtable.Rows.Add(derow)
                    End If
                Catch ex As FileIO.MalformedLineException
                    MessageBox.Show(ex.Message)
                End Try
                filtable.AcceptChanges()
                rws = myreader.ReadLine()
            End While
            myreader.Close()
      

  2.   

    感觉读入ArrayList会好一些
    ArrayList ar = new ArrayList();
     using (StreamReader sr = new StreamReader("f:\\abc.txt")) 
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null) 
                    {
                         ar.Add(line);
                    }
                }
      

  3.   

    using (StreamReader sr = new StreamReader("f:\\abc.txt")) 
    {
        string[] arr = sr.ReadToEnd().Split(new char[] {'\r','\n'});
    }
      

  4.   

    using (StreamReader sr = new StreamReader("f:\\abc.txt")) 
    {
        string[] arr = sr.ReadToEnd().Split(new char[] {'\r','\n'});
    }