无法写入文本文件

时间:2017-01-24 08:21:32

标签: vb.net

我有这段代码:

Dim tb As TextBox
Dim matches() As Control
Dim rtb2 As New RichTextBox
For i As Integer = 1 To 60
    matches = Me.Controls.Find("TextBox" & i, True)
    If matches.Length > 0 AndAlso TypeOf matches(0) Is TextBox Then
        tb = DirectCast(matches(0), TextBox)
        rtb2.AppendText(vbNewLine & "--" & vbNewLine & tb.Text)
    End If
    rtb2.savefile("thoikhoabieu.txt", RichTextBoxStreamType.PlainText)
Next

我使用此代码在vb中将文本写入文件,文件位于程序文件夹中,但是当我使用此代码时, thoikhoabieu.txt 文件没有任何内容。那是问题吗?我尝试过在vb中编写文本的替代方法但是失败了。

1 个答案:

答案 0 :(得分:0)

您只是保存文件但不写入文件。 尝试使用Stream Writer。 如果您不确定Path使用Directory.GetCurrentDirectory方法并在MsgBox中打印出您的路径

相关问题