如何在 VB.NET 中覆盖文本 [英] How do I overwrite text in VB.NET

查看:92
本文介绍了如何在 VB.NET 中覆盖文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经被教导如何使用以下代码附加文本文件,但是我每次按下按钮 1 时如何覆盖该文件(没有人教过我)?

I once got taught how to append a text file ussing the following code, but how do I overwrite the file every time I press button one (nobody taught me that)?

    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

下课

推荐答案

StreamWriter Constructor 的签名是这样的:

Signature of StreamWriter Constructor is this:

public StreamWriter(string path,bool append  )

所以改变你的代码:

System.IO.StreamWriter(ALPHAVAL, True)

到:

 System.IO.StreamWriter(ALPHAVAL, False)

这告诉 StreamWriter 覆盖文件.

这篇关于如何在 VB.NET 中覆盖文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆