streamwriter 覆盖问题
Dim cd As Date = Date.Now
Dim txt As String = cd.ToLongDateString + cd.ToLongTimeString
txt = txt.Replace(":", "")
txt = "" & txt1.Text + "" & txt + ".txt"
Dim fs As New FileStream(txt, IO.FileMode.OpenOrCreate)
'Dim sw As New StreamWriter(fs)
Using sw As StreamWriter = New StreamWriter(fs)
sw.writer(“A”)
sw.writerline()
sw.Flush()
sw.Close()
End Using
Process.Start(txt)
这个是我一个按钮实现的功能,当我第一次按下去时候TXT里面就一个A,但是当我按2次时候就出现2个A。我只想出现一个A。
我应该怎么修改?
[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As String
txt = "" & TextBox1.Text + "" + ".txt"
Dim fs As New FileStream(txt, FileMode.OpenOrCreate)
Using sw As StreamWriter = New StreamWriter(fs)
sw.Write("A")
sw.Flush()
sw.Close()
End Using
Process.Start(txt)
End Sub