本人属初学者小虾米,哪位大侠好心写下详细的代码。
含泪感激~

解决方案 »

  1.   

    我写的代码如下:
    string pathout="f:/11.txt";
    …… 
    StreamWriter sw= new StreamWriter(pathout ,true );
    sw.WriteLine(time[i] + " ");
    ……
    输出文件11.txt里面没有想要的time[]数组,请大虾们解救一下!
      

  2.   

                string pathout="f:\\11.txt";            StreamWriter sw= new StreamWriter(pathout ,true );
                string[] time=new string[100];
                for (int i = 0; i <= time.Length; i++)
                {
                    sw.WriteLine(time[i] + " ");
                }
                sw.Close();
                sw.Dispose();
    路径名不要弄错了
      

  3.   

    我的代码跟你的一样,但是11.txt文件里面还是没有写入,不知道是什么问题啊?
     StreamWriter sw = new StreamWriter(pathout, true);
                        for (int i = 0; i < 24; i++)
                        {
                             sw.WriteLine(time[i] + " ");
                        }
                        Console.ReadKey();
      

  4.   

    time在那赋值的,你看下文件大小是否有改变?完整代码贴出来看看。
      

  5.   

    sw.WriteLine(time[i].tostring() + " ");
      

  6.   

            
    static void Main(string[] args)
            {            string path = "f:/1.txt";
                string pathout="f:/11.txt";
                string[,] str = new string[24, 3];
                int[] time = new int[24];
                double[] p = new double[24];
                double[] e = new double[24];
                try
                {
                    FileStream fs = new FileStream(path, FileMode.Open);
                    using (StreamReader sr = new StreamReader(fs))
                    {                    string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", "");
                        string[] str2 = line.Split(' ');
                        for (int m = 0; m <24; m++)
                            for (int n = 0; n < 3; n++)
                            {
                                str[m, n] = str2[3 * m + n];
                                
                                for (int j = 0; j < 3; j++)
                                {
                                    for (int i = 0; i < 24; i++)
                                    {
                                        time[i] =Convert .ToUInt16 (str[i, 0]) ;
                                        p[i] =Convert .ToDouble (str[i, 1]) ;
                                        e[i] = Convert.ToDouble(str[i, 2]);
                                    }
                                }
                            }
                        StreamWriter sw = new StreamWriter(pathout, true);
                        for (int i = 0; i < 24; i++)
                        {
                             sw.WriteLine(time[i] + " ");
                        }
                        Console.ReadKey();
                    }
                }
                catch (Exception f)
                {
                    Console.Write("出现错误!{0}", f.Message);
                    Console.ReadKey();
                }        }
      

  7.   


    static void Main(string[] args)
    {string path = "f:/1.txt";
    string pathout="f:/11.txt";
    string[,] str = new string[24, 3];
    int[] time = new int[24];
    double[] p = new double[24];
    double[] e = new double[24];
    try
    {
    FileStream fs = new FileStream(path, FileMode.Open);
    using (StreamReader sr = new StreamReader(fs))
    {string line = sr.ReadToEnd().Replace("\r", "").Replace("\n", "");
    string[] str2 = line.Split(' ');
    for (int m = 0; m <24; m++)
    for (int n = 0; n < 3; n++)
    {
    str[m, n] = str2[3 * m + n];for (int j = 0; j < 3; j++)
    {
    for (int i = 0; i < 24; i++)
    {
    time[i] =Convert .ToUInt16 (str[i, 0]) ;
    p[i] =Convert .ToDouble (str[i, 1]) ;
    e[i] = Convert.ToDouble(str[i, 2]);
    }
    }
    }
    StreamWriter sw = new StreamWriter(pathout, true);
    for (int i = 0; i < 24; i++)
    {
    sw.WriteLine(time[i] + " ");
    }
    sw.close();
    Console.ReadKey();
    }
    }
    catch (Exception f)
    {
    Console.Write("出现错误!{0}", f.Message);
    Console.ReadKey();
    }}
     
      

  8.   

    就是你上边那个sw流没有关闭,调用sw.close();
      

  9.   

    StreamWriter rw = File.CreateText(Server.MapPath(".")+"\\CreateText.txt");
       rw.WriteLine("");
       rw.Flush();
       rw.Close();
    遍历数组