从TextStream 文件中读取指定数量的字符,并返回由此得到的字符串。
object.Read(characters)
下面的示例演示类如何使用 Read 方法来从文件中读取六个字符 Header,并返回获得的字符串:
[JScript] function GetHeader() { var fso, f; var ForReading = 1, ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true); f.Write("Header"); f.Write("1234567890987654321"); f.Close(); f = fso.OpenTextFile("c:\\testfile.txt", ForReading); return(f.Read(
6)
); } [VBScript] Function ReadTextFileTest Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso, f, Msg Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True) f.Write "Hello world!" Set f = fso.OpenTextFile("c:\testfile.txt", ForReading) ReadTextFileTest =f.Read(
5)
End Function
ReadAll 方法 | ReadLine 方法 | Skip 方法 | SkipLine 方法
应用于:TextStream 对象