none
我想把这个程序最后输出的结果写入文件。请问应怎么写? RRS feed

  • 问题

  •         {
                string cass = @"D:\cass.txt";

                string[] s0606 = null;

                s0606 = File.ReadAllLines("D:\\file\\0606text.txt");
                string[] dh = new string[2];
                string[] cc = new string[2*s0606.Length];
                string[] kg = new string[2];
                string[] cc2 = new string[6*s0606.Length];
                string[][] total= new string[60][];
               string[]total2= new string[60];


               /*// Console.WriteLine(s0606[0]);*/
                 foreach (string s in s0606)
                 {
                     Console.WriteLine(s);
                 }
        
                 Console.WriteLine("\n文件读取结束!下面进行修改!\n");
                char[] separator1 ={' '};
                char[] separator2 ={','};

                 int m = 0; int a = 0;
                for (int i = 12; i < s0606.Length; i++)
                {
                   
                    kg = s0606[i].Split(separator1);
                     int b = 0;
                    for (int n=0 ; n < 2;)
                    {
                        cc[m] = kg[n];
                        if (m > 0&&m%2!=0)
                        {
                            dh = cc[m].Split(separator2);
                            for (b = 0; b < 3; )
                            {
                                cc2[a] = dh[b];
                                a++; b++;
                            }
                          
                        }
                       
                         m++;  n++;
                    }

                }
                
                for(int h=0;h<360; h+=6)
                {
                        Console.WriteLine("{0},,{1},{2},{3}\n", cc2[h], cc2[h + 4], cc2[h + 3], cc2[h + 5]);
                 }

                Console.WriteLine("文件格式修改成功,下面进行写入文件");
                int t=0;int q=0;
                for (t = 0; t < 60; t++)
                {
                    total[t][0] = cc2[q];
                    total[t][1] = separator2.ToString();
                    total[t][2] = separator2.ToString();
                    total[t][3] = cc2[q + 4];
                    total[t][4] = cc2[q + 3];
                    total[t][5] = cc2[q + 5];
                    q += 6;
                }
               
                if (!File.Exists(cass))
                {
                  
                    // Create a file to write to.
                   

                    File.WriteAllLines(cass,);
                }

    新手,还请多多请教~

    2011年6月9日 5:55

答案

  • 原来定义一个 streamwriter writer=new streamwriter(……)

    writer.writline(……)

    就可以了。

    • 已标记为答案 timli 2011年6月9日 14:55
    2011年6月9日 14:55

全部回复