vb.net 列表框到文本文档没有覆盖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17644490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:15:24  来源:igfitidea点击:

listbox to text document no overwriting

vb.netlistboxdocumentsoverwrite

提问by user2581791

hello i am using this code to save listbox1 contents to .txt document it works. but as soon i reopen the program and save new text it overwriting original text how can i make it add as an additional text rather then overwriting. thank you so much every 1.

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

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()

回答by D_Bester

Try this

尝试这个

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

The true statement indicates that you want to append text to an existing file.

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

回答by Jeff

This is great!

这很棒!

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