如何操作文本文件??

lovingkiss 2003-10-19 09:55:51
请给出读写之类的例子~~
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
prok 2003-10-19
  • 打赏
  • 举报
回复
用StreamWriter ,
streamread
citylamp 2003-10-19
  • 打赏
  • 举报
回复
生成文件、写入文件、读取文件
Dim filetxt As System.IO.StreamWriter '生成StreamWriter对象
Try
filetxt = IO.File.CreateText("f:\\wbnet.txt") '生成文件
Catch err As Exception
MsgBox("Create file error!!")
End Try

filetxt.WriteLine("this is a file") '写入数据
filetxt.Close() '关闭文件

Dim filer As IO.TextReader
Try
filer = IO.File.OpenText("f:\\wbnet.txt")
Catch erro As Exception
MsgBox("Read error!")
End Try
Do While (filer.Peek <> -1) '读取文件内容
Dim str As String
str = filer.ReadLine
txtr.text = txtr.text + str
Loop
kncomputer 2003-10-19
  • 打赏
  • 举报
回复
fileopen函数,具体见vb.net的动态帮助。里面的内容很丰富。

fileopen(文件号,文件路径,打开方式)

例子:
如一文本文件c:\abc.txt内容如下:

两只老虎,两只老虎
跑得快,跑得快
一只没有眼睛,一只没有尾巴
真奇怪,真奇怪


----------
VB代码段:

dim s,s1 as string
FileOpen(1, "c;\abc.txt", OpenMode.Input)
Do While Not EOF(1)
s1 = LineInput(1)
s = s & s1 & vbCrLf
Loop
FileClose(1)
msgbox s

试试就知道。

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧