vb.net读写文本,vb读入文本文件

VB.net 读取文本文件

Imports System.IO

创新互联制作网站网页找三站合一网站制作公司,专注于网页设计,网站制作、成都网站设计,网站设计,企业网站搭建,网站开发,建网站业务,680元做网站,已为上千多家服务,创新互联网站建设将一如既往的为我们的客户提供最优质的网站建设、网络营销推广服务!

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

Dim sr As New StreamReader("d:\test.csv")

Dim arr1(), arr2(), arr3(), arr4() As Integer

Dim a1, a2, a3, a4 As New ArrayList

Do Until sr.EndOfStream

Dim str As String = sr.ReadLine

Dim s() As String = str.Split(",")

a1.Add(Convert.ToInt32(s(0)))

a2.Add(Convert.ToInt32(s(1)))

a3.Add(Convert.ToInt32(s(2)))

a4.Add(Convert.ToInt32(s(3)))

ListBox1.Items.Add(s(0))

Loop

arr1 = CType(a1.ToArray(GetType(Integer)), Integer())

arr2 = CType(a2.ToArray(GetType(Integer)), Integer())

arr3 = CType(a3.ToArray(GetType(Integer)), Integer())

arr4 = CType(a4.ToArray(GetType(Integer)), Integer())

sr.Close()

End Sub

End Class

如何用VB.net 读写Unicode编码的文本

不要用do until,用for:

Dim arr() As String, i As Integer

arr = Split(r.ReadLine, " ")

For i = LBound(arr) To UBound(arr)

MsgBox(arr(i))

Next

--------------------

还是用readline,如果你要提取两个非连续空格之间的字符串,可以用

Dim arr() As String

arr = Split(r.ReadLine, " ")

arr()数组里就存了你要的单词。

快要下班了,明后天不上班,如果16:30之前还搞不定就要下个星期1了。

----------------------------------

哈,是我的失误没想到还有可能有半角的日文。

用utf-8就OK了,代码如下:

(文本文件存的时候不能存成ansi,要存成utf-8,或是Unicode)

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

Dim r As System.IO.StreamReader

r = New System.IO.StreamReader("c:\a.txt", System.Text.Encoding.GetEncoding("utf-8"))

Do While Not r.EndOfStream

MsgBox(r.ReadLine)

Loop

End Sub

vb.net中,读取和写入文件

写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")

sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then

Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)

Dim sr As IO.StreamReader = New IO.StreamReader(fm)

Do While sr.Peek() = 0

TextBox1.Text = sr.ReadLine() (读取文本到文本框)

Loop end if

请教在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 读取文本文件?

1、实现上传按钮方法代码。

2、判断图片对象是否为空代码。

3、取得数据库字段 dt.Rows(0)("Pic")方法代码。

4、字节数组转换为Image类型方法代码。

5、处理SQL中操作Image类型方法代码。

6、实现的上传结果。

新闻标题:vb.net读写文本,vb读入文本文件
文章链接:https://www.cdcxhl.com/article42/hedoec.html

成都网站建设公司_创新互联,为您提供网站策划定制网站品牌网站制作标签优化网站排名电子商务

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发