ASP TextStream Object
The TextStream object is used to access the contents of text files.
Try it - Example
Reading a text file
This example demonstrates how to read content from a text file.
Reading a part of a text file
This example demonstrates how to read only part of the contents of a text stream file.
Reading a line from a text file
This example demonstrates how to read a line from a text stream file.
Reading All Lines of a Text File
This example demonstrates how to read all the lines from a text stream file.
Skipping a part of a text file
This example demonstrates how to skip a specified number of characters when reading a text stream file.
Skipping a line in a text file
This example demonstrates how to skip a line when reading a text stream file.
Returning the Line Count
This example demonstrates how to return the current line number in a text stream file.
Getting the Column Count
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), then writes some text to it (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:
property
| property | Description |
|---|---|
| AtEndOfLine | Returns True if the file pointer is positioned immediately before an end-of-line marker in a TextStream file; otherwise returns False. |
| AtEndOfStream | Returns True if the file pointer is at the end of a TextStream file; otherwise 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. |
Method
| 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 a whole line from a TextStream file (up to but not including the newline character) 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 specified text to a TextStream file. |
| WriteLine | Writes specified text and a newline character to a TextStream file. |
| WriteBlankLines | Writes a specified number of newline characters to a TextStream file. |