ASP TextStream Object

The TextStream object is used to access the contents of a text file.


More Examples

Read textfile
How to read from a text file.

Read only a part of a textfile
How to only read a part of a TextStream file.

Read one line of a textfile
How to read one line from a TextStream file.

Read all lines from a textfile
How to read all the lines from a TextStream file.

Skip a part of a textfile
How to skip a specified number of characters when reading the TextStream file.

Skip a line of a textfile
How to skip a line when reading the TextStream file.

Return line-number
How to return the current line number in a TextStream file.

Get column number
How to get the column number of the current character in a file.


The 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 the 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 or OpenTextFile methods of the FileSystemObject object, or you can use the OpenAsTextStream method of the File object.

The TextStream object's properties and methods are described below:

Properties

Property

Description

AtEndOfLine

Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file, and false if not

AtEndOfStream

Returns true if the file pointer is at the end of a TextStream file, and false if not

Column

Returns the column number of the current character position in an input stream

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 one line 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 a specified text to a TextStream file

WriteLine

Writes a specified text and a new-line character to a TextStream file

WriteBlankLines

Writes a specified number of new-line character to a TextStream file

 

ASP TextStream

Login
ADS CODE