Reads a specified number of characters from a TextStream file and returns the resulting string.
object.Read(characters)
The following example illustrates how to use the Read method to read a six character header from a file and return the resulting string:
[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 Method | ReadLine Method | Skip Method | SkipLine Method
Applies To: TextStream Object