软糖来告诉你吧.
VB.net中读写文件主要使用System.IO命名空间.
① 使用 File.ReadAllText 读取
Dim s As String = System.IO.File.ReadAllText("C:\a.txt")
② 使用 StreamReader 读取,注意编码格式和写入的编码保持一致.
Dim s As String = sr.ReadToEnd()
sr.Close()
③ 使用 File.WriteAllText 写入,会覆盖同名的文件.
Dim 要写的内容 As String = ""
④ 使用 StreamWriter 写入.
sw.WriteLine(TextTB.Text)
sw.Close()
⑤ 使用 StreamWriter 追加写入.
将上面代码的第二个参数False改为True.
+ 满意请采纳,谢谢 +
.net应该提供了此类函数.如C#就有File.AppendAllText(filename,string)用于追加内容,File.ReadAllLine(filename)用于读取多行.
一般来讲asp.net的服务器运行应用所用的账号只有对应用所在目录(放网页的目录)的访问权限,你可以把文件存储在应用所在目录或者子目录试试.
My.Computer.FileSystem.WriteAllText(Server.MapPath("") "\" Now.toString("yyyyMMdd") ".txt", "URL:XXXXXX查询完成,匹配成功!" vbCrLf, true, System.Text.Encoding.Default)
写入: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文件续读写的信息相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!