ASP TextStreamObject
The TextStream object is used to access the contents of text files.
Try it Yourself - Examples
Read a text file
This example demonstrates how to read contents from a text file.
Read a part of a text file
This example demonstrates how to read only part of a text stream file.
Read one line of a text file
This example demonstrates how to read one line from a text stream file.
Read all lines of a text file
This example demonstrates how to read all lines from a text stream file.
Skip a part of a text file
This example demonstrates how to skip a specified number of characters while reading a text stream file.
Skip a line of a text file
This example demonstrates how to skip a line while reading a text stream file.
Return the line number
This example demonstrates how to return the current line number in a text stream file.
Get the column number
This example demonstrates how to get the column number of the current character in a file.
TextStream Object
The TextStream object is used to access the contents of text files.
The following code creates a text file (c:\test.txt) and then writes some text to this file (the variable f is an instance of the TextStream object):
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("c:\test.txt",true)
f.WriteLine("Hello World!")
f.Close
set f=nothing
set fs=nothing
%>
To create an instance of the TextStream object, you can use the CreateTextFile method or the OpenTextFile method of the FileSystemObject object, or you can use the OpenAsTextStream method of the File object.
The properties and methods of the TextStream object are described below:
Properties
| Property | Description |
|---|---|
| AtEndOfLine | If the file pointer is positioned just before the end-of-line marker in a TextStream file, the property value returns True; otherwise, it returns False. |
| AtEndOfStream | If the file pointer is positioned at the end of a TextStream file, the property value returns True; otherwise, it returns False. |
| Column | Returns the column number of the current character position in the input stream of a TextStream file. |
| Line | Returns the current line number in a TextStream file. |
Methods
| Method | Description |
|---|---|
| Close | Closes an open TextStream file. |
| Read | Reads a specified number of characters from a TextStream file and returns the result. |
| ReadAll | Reads an entire TextStream file and returns the result. |
| ReadLine | Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the result. |
| Skip | Skips a specified number of characters when reading a TextStream file. |
| SkipLine | Skips the next line when reading a TextStream file. |
| Write | Writes the specified text to a TextStream file. |
| WriteLine | Writes the specified text and a newline character to a TextStream file. |
| WriteBlankLines | Writes a specified number of newline characters to a TextStream file. |
Other Extensions