private void button1_Click(object sender, EventArgs e)
        {
            FileStream fsInfo = new FileStream("e:/试题.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter swInfo = new StreamWriter(fsInfo,Encoding.Unicode);
            swInfo.Flush();
            swInfo.BaseStream.Seek(0, SeekOrigin.Begin);
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                string str=String.Empty;
                foreach (DataGridViewCell col in row.Cells)
                {
                    str += col.Value + "   ";                }
                str += swInfo.NewLine;
                swInfo.Write(str);                
            }            swInfo.Close();
}

解决方案 »

  1.   

    指明采用编码方式StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("UTF-8"));//通过指定字符编码方式可以实现对汉字的支持,否则在用记事本打开查看会出现乱码
     
      

  2.   

    StreamWriter swInfo = new StreamWriter(fsInfo,Encoding.Unicode);
    修改成这样看看?
    StreamWriter swInfo = new StreamWriter(fsInfo,Encoding.Default);
      

  3.   

    转码
    StreamWriter swInfo = new StreamWriter(fsInfo,Encoding.Default);
      

  4.   

    编码方式用UTF-8或者default