ASP TextStream



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


tryitimg.gif

Try it - Example

Reading a text file
This example demonstrates how to read content 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 a line from a text file
This example demonstrates how to read a 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 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 a text file
This example demonstrates how to skip a line when reading a text stream file.

Return the number of lines
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 the file.


TextStream object

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

The following code will create a text file (c:\test.txt) and then write 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 a TextStream object For an instance, 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 as follows:

Properties

PropertiesDescription
AtEndOfLineIf the file pointer is just before the end-of-line mark in the TextStream file, the value of this property returns True; otherwise, it returns False.
AtEndOfStreamIf the file pointer is at the end of the TextStream file, the property value returns True; otherwise, it returns False.
ColumnReturns the column number of the current character position in the TextStream file input stream.
LineReturns the current line number in the TextStream file.

Method

##CloseClose an open TextStream file. ReadReads the specified number of characters from a TextStream file and returns the result. ReadAllRead the entire TextStream file and return the result. ReadLineReads an entire line (up to but not including the newline character) from a TextStream file and returns the result. Skip Skip the specified number of characters when reading a TextStream file. SkipLine Skip the next line when reading a TextStream file. WriteWrite the specified text to a TextStream file. WriteLineWrite the specified text and newline characters to a TextStream file. WriteBlankLinesWrite the specified number of line breaks to a TextStream file.
MethodDescription