【发布时间】:2017-04-02 22:50:48
【问题描述】:
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 文件中。我怎样才能修改它,而不是删除数据,它只是附加到数据?
【问题讨论】:
-
为什么不能使用
File.AppendAllText()? -
文件每次都被覆盖,因为
CreateText就是这样做的。从msdn.microsoft.com/en-us/library/… 开始,此方法等效于将 append 参数设置为 false 的 StreamWriter(String, Boolean) 构造函数重载。如果 path 指定的文件不存在,则创建该文件。如果文件确实存在,则其内容将被覆盖。文件打开时允许其他线程读取文件。
标签: c# csv export-to-csv