可以写入 csv 文件但不能追加

2024-05-12

string pathDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        string filePath = pathDesktop + "\\mycsvfile.csv";
        string delimter = ",";
        string a = "Enoelpro---[037,033,0,018,030,012,004,021,009,038,035,053,044,050,074,F,018,010,070,000]<Vulpix>[-][037,034,0,022,020,029,002,008,024,036,046,049,041,057,077,F,018,005,070,000]<Vulpix>[-] cual es mejor??";
        List<string[]> test = conv(a,"testrainer");
        int length = test.Count;

        using (TextWriter writer = File.CreateText(filePath))
        {
            for (int index = 0; index < length; index++)
            {
                writer.WriteLine(string.Join(delimter, test[index]));
            }
        }

因此,目前,这工作正常,只是它不会将旧数据保留在 csv 文件中。我该如何修改它,而不是删除数据,而是简单地附加到数据中?


你可以尝试一下吗流写入器 https://msdn.microsoft.com/en-us/library/36b035cb(v=vs.110).aspx class?

如果该文件存在,则可以覆盖或附加该文件。如果该文件不存在,则此构造函数将创建一个新文件。

相反使用TextWriter writer = File.CreateText(filePath)尝试使用

TextWriter writer = new StreamWriter(filePath, true);

如果你通过了true在构造函数中,它应该将文本附加到文件中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

可以写入 csv 文件但不能追加 的相关文章

随机推荐