我现在文件里的结构如下
1 2 3 4 5 
6 7 8 9 10
11 12 13 14 15都是数字如何直接将这些一个一个读取出来存到数组里是txt文件谢谢大家 我现在只知道怎么写入字符串。

解决方案 »

  1.   

    会写不会读....
    一行行读,split 分割空格,逐一加到数组
      

  2.   

    String s = String.ReadFile(文本文件)
    String[] ss = s.Split('')
    Int[] arr=new Int[ss.Length]
    For(int i=0;i<ss.Length;i++)
    {
       arr[i]=Int.Parse(ss[i])
    }
      

  3.   


    string[] test;
    string line;
    FileStream ifs = new FileStream("test.txt",FileMode.Open);
    StreamReader sr = new StreamReader(ifs);
    while(line = sr.ReadLine()!=null)
    {
        test = line.Split(' ');
    }
    ifs.Close();
    sr.Close();
      

  4.   


    var strNums = File.ReadAllText(fileName);var ret = strNums.Split(
        new char[] {' ', '\r' , '\n'},
        StringSplitOptions.RemoveEmptyEntries)
        .Select(num => Convert.ToInt32(num)).ToArray();Console.WriteLine(string.Join(",", ret));
      

  5.   

    Use the Microsoft Access Database Engine OLE DB provider to access data in a text file. 
      

  6.   

    string path = @"D:\test.txt";//读取文件txt
            List<string> list = new List<string>() ;
            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    while (!sr.EndOfStream)
                    {
                        string sLine = sr.ReadLine();
                        if (sLine.Length < 1)
                        {
                            continue;
                        }
                        list.Add(sLine);
                   }
                }
            }
      

  7.   

    1 2 3 4 5
    6 7 8 9 10
    11 12 13 14 15
    string path = @"D:\1.txt";//读取文件txt
            List<string> list = new List<string>();
            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    while (!sr.EndOfStream)
                    {
                        string sLine = sr.ReadLine();
                        if (sLine.Length < 1)
                        {
                            continue;
                        }
                        string[] test1 = sLine.Split(' ');//过滤空格
                        foreach (string s in test1)
                        {
                           list.Add(s.Trim());
                        }
                    }
                }
            }测试了下不知道适合你不