我正在制作文件加密器/解密器,但遇到FSO.ReadAll
无法读取整个文件内容的问题。
下面是代码:
Sub EncryptFile(file)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set readf = FSO.OpenTextFile(file, 1)
c = readf.ReadAll
readf.Close()
Set readf = Nothing
'MsgBox only shows the first 4 characters of the file. ("ÿØÿà")
'Does ReadAll stop its reading when the character is unreadable for it?
'n = MsgBox(c, , "")
'^^^^^ Result: ÿØÿà
'...more below, but no longer needed for the question
End Sub
MsgBox
结果:
文件内容(是,文件为.JPG)
似乎是什么问题?是因为ReadAll
停止阅读是因为编码或其他内容无法读取下一个字符吗?
答案 0 :(得分:0)
ReadAll并不用于读取二进制文件。
尝试使用读取功能代替。
Sub EncryptFile(file)
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim objFile: Set objFile = oFSO.GetFile(file)
Set readf = FSO.OpenAsTextStream()
c = readf.Read(objFile.Size)
readf.Close()
Set readf = Nothing
End Sub