列表框到文本文档没有覆盖

时间:2013-07-14 22:38:37

标签: vb.net listbox documents overwrite

您好我正在使用此代码将listbox1内容保存到.txt文档中。但是,一旦我重新打开程序并保存新文本,它会覆盖原始文本,如何将其添加为附加文本而不是覆盖。非常感谢你们每一次。

Dim W As IO.StreamWriter
Dim i As Integer
W = New IO.StreamWriter("C:\test\test.txt")

For i = 0 To ListBox2.Items.Count - 1
    W.WriteLine(ListBox2.Items.Item(i))
Next
W.close()

2 个答案:

答案 0 :(得分:3)

试试这个

W = New IO.StreamWriter("C:\test\test.txt", True)

true语句表示您要将文本附加到现有文件。

答案 1 :(得分:-1)

这很棒!

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Dim count As Integer = System.IO.File.ReadAllLines("location").Length
    If count <= 9 Then
        MsgBox("less then 10")
    Else
        MsgBox("more then 10")
    End If
End Sub