lof返回的是字节数
而VB的字符串是以一个UniCode字符作为单位
读取:
Dim TempFile As Long
Dim LoadBytes() As Byte
TempFile=FreeFile
Open 文件名 For Binary As #TempFile
Redim LoadBytes(1 To Lof(TempFile)) As Byte
Get #TempFile,,LoadBytes
Close TempFile
Text1.Text=StrConv(LoadBytes,vbUniCode)
写入:
Dim TempFile As Long
Dim SaveBytes() As Byte
SaveBytes=StrConv(Text1.Text,vbFromUniCode)
TempFile=FreeFile
Open 文件名 For Binary As #TempFile
Put #TempFile,,SaveBytes
Close TempFile
复制文件:
Public Sub MyCopy(SFile As String, DFile As String)
Dim TempFile As Integer
Dim TempBytes() As Byte
Dim FileLen As Long
TempFile = FreeFile
Open SFile For Binary As #TempFile
FileLen = LOF(TempFile)
ReDim TempBytes(1 To FileLen)
Get #TempFile, , TempBytes
Close #TempFile
Open DFile For Binary As #TempFile
Put #TempFile, , TempBytes
Close #TempFile
End Sub
VB读写
最新推荐文章于 2023-08-03 18:12:57 发布