using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ciles
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            FileInfo f = new FileInfo(@"c:\ciles.txt");
            StreamWriter w = f.CreateText();
            int count = 0;
            for (count=0; count <= 720; count++)
            {
                w.Write("{0,4}", count);
                w.Write(".000000 ");                if (count % 5 == 0)
                    w.Write("\r\n");
            }            for (count=721; count<=1720;count++ )
            {
               
                            w.Write("{0,4}", count);
                            w.Write(".176700 ");
                            if (count % 5 == 0)
                                w.Write("\r\n");
               
            }        }
    }
}
问题很简单, 就是要写1720个数据,每行写5个,可是最后写出来的只有1651个,
这段代码是非常简单的,但是我看了好几遍实在是看不出有什么问题,搞不懂.

解决方案 »

  1.   

    还真是因为这个,谢谢啊
    但是我想不通,为什么没写w.close()就会这样呢?
    既不是全写不出来,也不是全写出来,而只是最后的几个写不出来呢.
      

  2.   

    不是啊,只要加上w.close()就是成功的,况且程序很简单,就那么几行。
      

  3.   

    可能是因为在缓冲区中的数据没有满,还没有写到文件中,在CLOSE时就会把剩下的内容写进去了
      

  4.   

    那是FileStream自己带了缓冲区的缘故,最后几行没有填满缓冲区就不会写到实际文件中。