我正在尝试创建一个将记录添加到csv文件末尾的过程
Sub AddRecord()
Dim NewRecord As String
Console.WriteLine("Enter the record you wish to add")
NewRecord = Console.ReadLine()
Console.WriteLine("Done")
Using writer As StreamWriter = File.AppendText(FileName)
writer.WriteLine(NewRecord)
End Using
Console.ReadLine()
End Sub
如果NewRecord =测试,测试,测试,测试程序执行此操作
Town,County,Pop,Area
Berwick-upon-tweed,Nothumberland,12870,468
Bideford,devon,16262,430
Bognor Regis,West Sussex,62141,1635
Bridlington,East Yorkshire,33589,791
Bridport,Dorset,12977,425
Cleethorpes,Lincolnshire,31853,558
Colwyn bay,Conway,30269,953
Dover,Kent,34087,861
法尔茅斯,康沃尔郡,21635,543
Great Yarmouth,Norfolk,58032,1467
Hastings,East Sussex,85828,1998测试,测试,测试,测试
但我希望在hastings记录之后将测试,测试,测试,测试添加到记录中,我该如何解决这个问题?
答案 0 :(得分:0)
文件操作很快。不要在类级别使用任何流。打开,添加,关闭。 File.AppendText
Using sw As StreamWriter = File.AppendText({path})
sw.WriteLine({record})
End Using