写入文件中的特定行,VB2008

时间:2014-06-29 15:16:27

标签: vb.net

是否可以使用数组将多个文本框写入文本文件中的多行而不更改文本文件的其余部分?我用过这个:

'Write co-ordinates into KML file
Dim line() As String = System.IO.File.ReadAllLines([filepath]\A.kml")
line(19) = A2.Text
System.IO.File.WriteAllLines("[filepath]\A.kml", line)

但它会取代它下面的内容。

由于

1 个答案:

答案 0 :(得分:-1)

你可以试试这个:

Dim List As New List(Of String)
Dim Writer As New StreamWriter(<filepath+filename>)
Dim Reader As New StreamReader(<filetoread>)

Do Until Reader.EndOfStream
    List.Add(Reader.ReadLine())
Loop

List(19) = A2.Text

For Each s As String In List
    Writer.WriteLine(s)
Next

Writer.Close()