你把全部都读进去,因为我的机子上没装C#,没帮助文档,
某一个流类有一个readtoend函数,全部都读进去,作为一个字符串来处理在字符串类中有一个函数,可以用来根据空格来把字符串分成数组的函数.这样你就可以把数据读到一个字符串数组里了.这样你用的时候转换一下就可以了!希望可以帮上忙,不行的话,可以直接联系我[email protected]

解决方案 »

  1.   

    FileInfo file = new FileInfo(path);
    string content = file.OpenText().ReadToEnd();
    string[] items = content.Replace("\r","")Split('\n');
      

  2.   

    try:using System;
    using System.IO;
    using System.Text.RegularExpressions;class ReadFile{
      static void Main(){
        double[][] points = GetData("1.txt");
        for(int i = 0; i < points.Length; i++){
         Console.WriteLine();
           for(int j = 0; j < points[i].Length; j++)
              Console.Write(points[i][j]);
            }
      }
      
      static double[][] GetData(string fileName){
        Stream stream = new FileStream(fileName,FileMode.Open,FileAccess.Read);
        StreamReader reader = new StreamReader(stream);
        string content = reader.ReadToEnd(); 
        reader.Close();
        string[] line = content.Split(new char[]{'\n'});
        double[][] result = new double[line.Length][];
        for(int i = 0 ; i < result.Length; i++)
          result[i] = new double[2]; 
        Regex r = new Regex(@"\s+");
        for(int i = 0 ; i < result.Length; i++){
          string[] cols = r.Split(line[i]);
          for(int j = 0; j < result[i].Length; j++)
             result[i][j] = double.Parse(cols[j]);}
       return result;
      }
    }
      

  3.   

    Regex r = new Regex(@"\s+");
    什么意思?
    我的两个数之间有4个空格
    该如何处理?
      

  4.   

    >>>>Regex r = new Regex(@"\s+");
    什么意思?
    我的两个数之间有4个空格
    该如何处理?Regex r = new Regex(@"\s+");//正则表达式,至少一个空白符
    //...
    string[] cols = r.Split(line[i]);//分割line[i]
    line[i] 表示的就是每一行的数据,分割后(以第一行为例):
    cols[0] = 0.0000
    cols[1] = -0.6511
      

  5.   

    >>>>>因为点是整数,而数据是实数他们如何映射?????double[][] pt= GetData(@"1.txt");
     PointF[] pts = new PointF[pt.Length];
                for(int i = 0; i < pts.Length; i++)
     pts[i] = new PointF((float)pt[i][0],(float)pt[i][1]);
     this.CreateGraphics().DrawLines(new Pen(this.ForeColor),pts );//注意:你的pt[i][1]是负数,转换的时候你的pt[i][1]可能要乘以一个负数(如-200),否则你将看不到画出来的线