vb.net按行读文本 vbnet readline 语句
如何用vb.net编写读取txt内容的代码?
窗体上添加2个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。
创新互联主营玉泉网站建设的网络公司,主营网站建设方案,app软件开发,玉泉h5微信小程序搭建,玉泉网站营销推广欢迎玉泉等地区企业咨询
代码如下:
'写文本文件
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文件,想按行读取全部内容,然后显示在一文体框中,代码如下
a = ""
TextBox1.Text =""
FileOpen(1, Application.StartupPath() "\file\t1.txt", OpenMode.Input)
Do While Not EOF(1)
Input(1, a)
TextBox1.Text =TextBox1.Text a vbcrlf
Loop
一次性读取
a=File.ReadAllText(Application.StartupPath() "\file\t1.txt")
vb.net 按行读取字符串
给你一个VB2010读写文件的例子吧
Dim name As String = ""
Dim age As Integer
name = InputBox("请输入姓名")
age = InputBox("请输入年龄")
FileOpen(1, "d:\信息.txt", OpenMode.Append)
WriteLine(1, name, age)
FileClose(1)
FileOpen(1, "d:\信息.txt", OpenMode.Input)
Dim h As String
Dim j As String
Dim f As String
f = ""
h = ""
j = ""
While EOF(1) = False
f = LineInput(1) vbCrLf f
End While
FileClose(1)
MsgBox("姓名" " " "年龄" vbCrLf f)
网站名称:vb.net按行读文本 vbnet readline 语句
文章链接:http://scyanting.com/article/ddodegc.html