ASP TextStream Object
- Previous Page ASP FileSystem
- Next Page ASP Drive
The TextStream object is used to access the content of text files.
Example
- Read a file
- This example demonstrates how to create a TextStream object using the OpenTextFile method of the FileSystemObject. The ReadAll method of the TextStream object retrieves the content from the opened text file.
- Read a part of the text file
- This example demonstrates how to read only a part of the content from a text stream file.
- Read a line from the text file
- This example demonstrates how to read a single line from a text stream file.
- Read all lines of the text file
- This example demonstrates how to read all lines from a text stream file.
- Skip a part of the text file
- This example demonstrates how to skip a specified number of characters when reading a text stream file.
- Skip a line in the text file
- This example demonstrates how to skip a line when reading a text stream file.
- Return line number
- This example demonstrates how to return the current line number in the text stream file.
- Get column number
- This example demonstrates how to obtain the column number of the current character in the file.
TextStream object
The TextStream object is used to access the content of text files.
The following code creates a text file (c:\test.txt) and then writes some text to this file (variable f is an instance of a 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 a TextStream object, we can use the CreateTextFile method or OpenTextFile method of the FileSystemObject object, or we can use the OpenAsTextStream method of the File object.
The properties and methods of the TextStream object are described as follows:
Property
Property | Description |
---|---|
AtEndOfLine | In the TextStream file, if the file pointer is exactly before the line end marker, this property returns True; otherwise, it returns False. |
AtEndOfStream | If the file pointer is at the end of the TextStream file, this property returns True; otherwise, it returns False. |
Column | Return the column number of the current character position in the TextStream file. |
Line | Return the current line number in the TextStream file. |
Method
Method | Description |
---|---|
Close | Close an open TextStream file. |
Read | Read a specified number of characters from a TextStream file and return the result (the resulting string). |
ReadAll | Read the entire TextStream file and return the result. |
ReadLine | Read an entire line from a TextStream file (up to the newline character but not including the newline character) and return the result. |
Skip | When reading a TextStream file, skip the specified number of characters. |
SkipLine | When reading a TextStream file, skip the next line. |
Write | Write a specified text (string) to a TextStream file. |
WriteLine | Write a specified text (string) and a newline character to a TextStream file. |
WriteBlankLines | Write a specified number of newline characters to a TextStream file. |
- Previous Page ASP FileSystem
- Next Page ASP Drive