加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb6.0 快速读取txt

发布时间:2020-12-17 08:12:40 所属栏目:百科 来源:网络整理
导读:Function GetFile(FileName As String) As StringDim i As Integer,s As String,BB() As ByteIf Dir(FileName) = "" Then Exit Functioni = FreeFileReDim BB(FileLen(FileName) - 1)Open FileName For Binary As #iGet #i,BBClose #is = StrConv(BB,vbUnico
Function GetFile(FileName As String) As String
Dim i As Integer,s As String,BB() As Byte
If Dir(FileName) = "" Then Exit Function
i = FreeFile
ReDim BB(FileLen(FileName) - 1)
Open FileName For Binary As #i
Get #i,BB
Close #i
s = StrConv(BB,vbUnicode)
GetFile = s
End Function

'调用举例:
dim s as string
s=GetFile("c:1.txt")
如果文件中没有中文字符,那么下面代码读整个文件的速度是非常快的,我读了一个6M的文件,只用了不到1秒。如果有中文字符,就需要把s = Input$(LOF(1),#1)中的LOF(1)减去中文字符数量。
Dim r As String,s As String
r = Environ("userprofile")
r = r + "桌面9898.txt"'要读的文件路径,在桌面上的9898.txt
Open r For Input As #1
s = Input$(LOF(1),#1)
Debug.Print s
Close #1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读