TextStream Object
Facilitates sequential access to file.
TextStream.{property | method( )}
Arguments
The property and method arguments can be any of the properties and methods associated with the TextStream object. Note that in actual usage, TextStream is replaced by a variable placeholder representing the TextStream object returned from the FileSystemObject.
Remarks
The following example illustrates the use of the TextStream object.
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Create the file, and obtain a file object for the file.
var filename = "c:\\testfile.txt";
fso.CreateTextFile(filename);
var fileObj = fso.GetFile(filename);
// Open a text stream for output.
var ts = fileObj.OpenAsTextStream(ForWriting, TristateUseDefault);
// Write to the text stream.
ts.WriteLine("Hello World!");
ts.WriteLine("The quick brown fox");
ts.Close();
// Open a text stream for input.
ts = fileObj.OpenAsTextStream(ForReading, TristateUseDefault);
// Read from the text stream and display the results.
while (!ts.AtEndOfStream) {
var textLine = ts.ReadLine();
document.write (textLine + "<br />");
}
ts.Close();
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, ts, fileObj, TextLine, FileName
Set fso = CreateObject("Scripting.FileSystemObject")
' Create the file, and obtain a file object for the file.
FileName = "c:\testfile.txt"
fso.CreateTextFile FileName
Set fileObj = fso.GetFile(FileName)
' Open a text stream for output.
Set ts = fileObj.OpenAsTextStream(ForWriting, TristateUseDefault)
' Write to the text stream.
ts.WriteLine "Hello World!"
ts.WriteLine "The quick brown fox"
ts.Close
' Open a text stream for input.
Set ts = fileObj.OpenAsTextStream(ForReading, TristateUseDefault)
' Read from the text stream and display the results.
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
Document.Write TextLine & "<br />"
Loop
ts.Close
Methods
Close Method | Read Method | ReadAll Method | ReadLine Method | Skip Method | SkipLine Method | Write Method | WriteBlankLines Method | WriteLine Method
Properties
AtEndOfLine Property | AtEndOfStream Property | Column Property | Line Property
See Also
Reference
Change History
Date |
History |
Reason |
---|---|---|
September 2010 |
Modified examples. |
Information enhancement. |