网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.net写文件,net vb

请教,vb.net写入文件问题,为什么我用两种办法写文件只能写入最后一行

写入模式为覆盖会出现这个现象

成都创新互联专业为企业提供浚县网站建设、浚县做网站、浚县网站设计、浚县网站制作等企业网站建设、网页设计与制作、浚县企业网站模板建站服务,十载浚县做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

要使用添加模式

就会累加了

请教在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中,读取和写入文件

写入: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怎么往已经建立好的dat文件里写东西,还不覆盖原本的数据?

如果想继续编辑之前的文档,在TXT文件尾部继续添加文本,那么还需要在函数后边加个参数。

VB 代码

方法1:

  Dim sw As StreamWriter = New StreamWriter("C:\temp\test.txt")

  sw.Write("abc"  vbCrLf)

sw.Close()

Dim sw2 As StreamWriter = New StreamWriter("C:\temp\test.txt", True)

sw2.Write("456"  vbCrLf)

sw2.Close()

方法2:

  My.Computer.FileSystem.WriteAllText("test.txt", "This is test Text", True)

方法3:

  System.IO.File.AppendAllText("c:\temp\test.txt", "this is extra test file")

详见:“网页链接” 

关于VB.NET的写入文件

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

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

Dim i As Integer = 0

For i = 0 To Val(TextBox4.Text)

aa.WriteLine("[" i "]")

aa.WriteLine("[" i "]")

Next

aa.Close()

aa.Dispose()

End Sub


本文名称:vb.net写文件,net vb
URL分享:http://bjjierui.cn/article/dsidhpe.html

其他资讯