Vbscript FSO.ReadAll不读取整个文件内容

Vbscript FSO.ReadAll不读取整个文件内容,vbscript,Vbscript,我在制作一个文件加密/解密程序时遇到了一些问题,即FSO.ReadAll无法读取整个文件的内容 代码如下: Sub EncryptFile(file) Set FSO = CreateObject("Scripting.FileSystemObject") Set readf = FSO.OpenTextFile(file, 1) c = readf.ReadAll readf.Close() Set readf = Nothing 'MsgBo

我在制作一个文件加密/解密程序时遇到了一些问题,即
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
停止读取,因为下一个字符对于编码或其他任何东西都不可读吗?

ReadAll不是用于读取二进制文件的

尝试改用read函数

 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

请参阅:

c字符串以第5个字符的null结尾。PS
c
(一个bstr,其中null没有任何意义)确实包含整个文件,但任何需要字符串的api调用都将在第5个字符处终止。正在读取它们,但无法打印为任何需要cstr的内容,所有api调用。你显然不想把它放在msgbox里。那么你想用它做什么呢?为什么要使用
ascw
?我不希望
OpenTextFile
能可靠地处理非文本文件。(请在vbscript中查找
ADODB.Stream
)@您必须解释一下,我已经多次使用
ADODB.Stream
读取原始二进制文件。VBScript中的二进制支持很差,但并非不可能。您是对的,但是在这种情况下使用
AscW()
毫无意义,可能会导致结果混乱。