如何逐行读文本文件的内容?

aalan 2005-08-29 04:04:44
请教一下:
如何逐行读文本文件的内容?能给段例子将不胜感激
...全文
334 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aalan 2005-08-29
  • 打赏
  • 举报
回复
谢谢,用VBToy的方法解决
yinweihong 2005-08-29
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4235/4235585.xml?temp=.6353418
conrad_wan 2005-08-29
  • 打赏
  • 举报
回复
studying。。。
VBToy 2005-08-29
  • 打赏
  • 举报
回复
fn="C:\test.txt"
dim lineStr as string, strFile as string
Open Fn For Input As #1
Do While Not EOF(1)
Line Input #1, lineStr
strFile = strFile & lineStr
DoEvents
Loop
Close #1
myhgyp 2005-08-29
  • 打赏
  • 举报
回复
Option Explicit
'引用Microsoft Scripting Runtime
Private Sub Form_Load()
Dim oFSO As FileSystemObject
Dim oTextStream As TextStream
Dim oFirstLine As String
Dim i, LineNum As Integer
Set oFSO = CreateObject("scripting.filesystemobject")
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForAppending, False, TristateFalse)
oTextStream.Write (vbCrLf & "这是一个新增的测试行")

'以下为删除某一行,如第二行
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForReading, False, TristateFalse)
Dim str(1000) As String '这里根据实际情况可增大或缩小数组的维数
i = 0
Do While oTextStream.AtEndOfLine <> True
str(i) = oTextStream.ReadLine '读取一行
i = i + 1
Loop
LineNum = i
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForWriting, False, TristateFalse)
oTextStream.Write str(0)
For i = 1 To LineNum - 1
If i <> 1 Then
oTextStream.Write vbCrLf & str(i)
End If
Next i
oTextStream.Close
Set oFSO = Nothing
End Sub
zhoumins 2005-08-29
  • 打赏
  • 举报
回复
System.IO.StreamReader stream=System.IO.File.OpenText(@"d:\csdn.txt");
string str;
while((str=stream.ReadLine())!=null)
{
Response.Write(str+"<br>");
}

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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