To access the contents of a text file,the TextStream object is used .
A D V E R T I S E M E N T
The TextStream Object
To access the contents of a text file,the TextStream object is used .
The following code creates a text file (D:\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("D:\test.txt",true)
f.WriteLine("Hello World!")
f.Close
set f=nothing
set fs=nothing
%>
You can use the CreateTextFile or OpenTextFile methods of the
FileSystemObject object or you can use the OpenAsTextStream
method of the File object to create an instance of the TextStream 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
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
Read Text File
<html>
<body>
<p>This is the text in the text file:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadAll)
f.Close