【问题标题】:listbox to text document no overwriting列表框到文本文档没有覆盖
【发布时间】:2013-07-12 17:48:27
【问题描述】:

您好,我正在使用此代码将 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()

【问题讨论】:

    标签: vb.net listbox documents overwrite


    【解决方案1】:

    试试这个

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

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

    【讨论】:

    • 非常感谢你是他最好的作品,我给你留下了 1 个积极的反馈欢呼
    【解决方案2】:

    这太棒了!

    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
    

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 2018-04-25
      • 2013-11-25
      • 2023-02-17
      • 1970-01-01
      相关资源
      最近更新 更多