我曾经教过如何使用以下代码附加文本文件,但是每次按下按钮1时,如何覆盖文件(没有人教过我)?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ALPHAVAL As String = "C:\ALPHAVAL.txt"
If System.IO.File.Exists(ALPHAVAL) = True Then
Dim objWriter As New System.IO.StreamWriter(ALPHAVAL, True)
objWriter.WriteLine(TextBox1.Text)
objWriter.Close()
End If
结束课
答案 0 :(得分:8)
StreamWriter构造函数的签名是这样的:
public StreamWriter(string path,bool append )
所以改变你的代码:
System.IO.StreamWriter(ALPHAVAL, True)
到:
System.IO.StreamWriter(ALPHAVAL, False)
告诉StreamWriter覆盖文件。