快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

包含vb.net写txt的词条

vb.net创建一个txt文本,在debug文件夹里

设计一个窗口,添加一个名为textBox1的System.Windows.Forms.TextBox,

成都创新互联-专业网站定制、快速模板网站建设、高性价比临翔网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式临翔网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖临翔地区。费用合理售后完善,十余年实体公司更值得信赖。

添加一个名为button1的System.Windows.Forms.Button。

为button1的单击事件添加如下处理函数:

Sub Button1Click(sender As Object, e As EventArgs)

'f是你的文本文件的文件名

Const f As String="t.txt"

Dim sw As System.IO.StreamWriter=Nothing

Try

If Not System.IO.File.Exists(f) Then

sw=System.IO.File.CreateText(f)

Else

sw=New System.IO.StreamWriter(f,True)

End If

sw.WriteLine(textBox1.Text)

Finally

If sw IsNot Nothing Then

sw.close()

End If

End Try

End Sub

vb.net 中对txt文件的读取、写入的方法!始终保持txt里面只有一行!

Public Class Form1

Private Sub 写入文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 写入文件.Click

FileOpen(1, "D:\一行文件.txt", OpenMode.Output) ' Open file for output.

WriteLine(1, "想只保留文件为一行 那你就写一行好了") ' Print blank line to file.

FileClose(1) ' Close file.

End Sub

Private Sub 读取文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 读取文件.Click

Dim TextLine As String

FileOpen(1, "D:\一行文件.txt", OpenMode.Input) ' Open file for output.

TextLine = LineInput(1) '读取一行就了

MsgBox(TextLine)

FileClose(1)

End Sub

End Class

最简单的方法 还有很多方法 自己研究吧亲 希望能帮到你

请教在VB.net中如何将数据写入txt文件、再从txt文件读出?

软糖来告诉你吧。

VB.net中读写文件主要使用System.IO命名空间。

① 使用 File.ReadAllText 读取

Dim s As String = System.IO.File.ReadAllText("C:\a.txt")

② 使用 StreamReader 读取,注意编码格式和写入的编码保持一致。

Dim sr As StreamReader = New StreamReader("C:\a.txt", System.Text.Encoding.UTF8)

Dim s As String = sr.ReadToEnd()

sr.Close()

③ 使用 File.WriteAllText 写入,会覆盖同名的文件。

Dim 要写的内容 As String = ""

File.WriteAllText(文件路径, 要写的内容, System.Text.Encoding.UTF8)

④ 使用 StreamWriter 写入。

Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("C:\a.txt", False, System.Text.Encoding.UTF8)

sw.WriteLine(TextTB.Text)

sw.Close()

⑤ 使用 StreamWriter 追加写入。

将上面代码的第二个参数False改为True。

◆ 满意请采纳,谢谢 ◆

如何用vb.net编写读取txt内容的代码?

窗体上添加2个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。

代码如下:

'写文本文件

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'创建(写入)一个文本文件

Dim MyStream As New System.IO.FileStream(Application.StartupPath "\Ssk.txt", System.IO.FileMode.Create)

Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.Default)

MyWriter.WriteLine(TextBox1.Text)

MyWriter.Flush()

MyWriter.Close()

MyStream.Close()

End Sub

'读文本文件

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'读取一个文本文件

Dim MyReader As New System.IO.StreamReader(Application.StartupPath "\Ssk.txt", System.Text.Encoding.UTF8)

TextBox2.Text = MyReader.ReadToEnd()

MyReader.Close()

End Sub

气斜射入水或其他介质,折射光线与入射光线法线在


网页名称:包含vb.net写txt的词条
URL链接:http://6mz.cn/article/dospgjg.html

其他资讯