【问题标题】:Why is my C# Writer.Write(Filelist1) only writing 1kb为什么我的 C# Writer.Write(Filelist1) 只写 1kb
【发布时间】:2019-08-15 00:32:45
【问题描述】:

从 i is nub 开始 我正在编写一个应用程序以使用文本文件中的链接列表从 curseforge 下载 mods,当我尝试使用表单中的文本框写入该文件时

private void textBox1_TextChanged(object sender, EventArgs e)
{
    //this code segment write data to file.
    FileStream fs1 = new FileStream("Addons.AMU", FileMode.OpenOrCreate, FileAccess.ReadWrite);
    StreamWriter writer = new StreamWriter(fs1);
    writer.Write(FileList1);
    writer.Flush();
    writer.Close();

}

但是,当我阅读它打印的文件时 System.Windows.Forms.TextBox,文本:(这里是乱码)...

为什么它会打印几个字符然后...?

如果我写

hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!

我希望输出与输出完全相同,但输出为

System.Windows.Forms.TextBox, Text: hello world!
hello world!
hello world!....

【问题讨论】:

  • 你打电话给writer.Write(FileList1);。那是试图将TextBox 对象本身写给作者。我怀疑你的意思是writer.Write(FileList1.Text);
  • 感谢您的帮助,我真的很感激

标签: c# streamwriter


【解决方案1】:

尝试改变

writer.Write(FileList1);

writer.Write(FileList1.Text);

【讨论】:

  • 我的上帝,真是太快了,感谢您的帮助,我真的很感激
猜你喜欢
  • 2021-04-10
  • 1970-01-01
  • 2010-10-09
  • 2014-01-04
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 2018-09-04
  • 1970-01-01
相关资源
最近更新 更多