首页 > 解决方案 > 为什么我的 C# Writer.Write(Filelist1) 只写 1kb

问题描述

当我尝试使用表单中的文本框写入该文件时,我正在编写一个应用程序以使用文本文件中的链接列表从 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, Text: (random bs gibberish here)...

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

如果我写

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!....

标签: c#streamwriter

解决方案


尝试改变

writer.Write(FileList1);

writer.Write(FileList1.Text);

推荐阅读