"TextStream" Class - Input or Output Stream
This section provides a tutorial example on how to use the TextStream class that represents an input or output stream connected to a file. TextStream class is provided in the Scripting Runtime DLL, scrrun.dll.
TextStream: A class representing an input or output stream connected to a file. It offers the following
properties and methods:
- "AtEndOfLine": Property to return true if the current reading position is before
the end of a line.
- "AtEndOfStream": Property to return true if the current reading position is before
the end of the file.
- "Column": Property to return the column number of the current position.
- "Line": Property to return the line number of the current position.
- "Read(n)": Method to return a string of characters up to the specified number.
- "ReadAll()": Method to return a string of the rest characters in the stream.
- "ReadLine()": Method to return a string of the rest characters in the line.
Here is a sample ASP page to show you how to create and open a text file.
<script language="vbscript" runat="server">
' Copyright (c) 1999 by Dr. Herong Yang
' This program shows how to create and open files as text stream
response.write("<b>Tests on the TextStream class</b>:<br/>")
' Getting the FileSystemObject
set fs = CreateObject("Scripting.FileSystemObject")
' Creating a new file for writing
set out = fs.CreateTextFile("c:\temp\test.txt",true,false)
' Open an existing file for reading
set inn = fs.OpenTextFile("c:\temp\test.txt",1)
while inn.AtEndOfStream = false
line = inn.ReadLine()
response.write(line & "<br/>")
Tests on TextStream class:
- If you look at the directory c:\temp, you will a new file "test.txt".
- You can not create new files in c:\inetpub\wwwroot. If you try, you will get
"permission denied" error message.
- "in" seems to be a reserved word. So I used "inn" as a variable name.
- "wend" ends the "while" statement. I really don't know why the designers can
not use "end while".
Last update: 2002.
Table of Contents
About This Book
ASP (Active Server Pages) Introduction
IIS (Internet Information Services) 5.0
MS Script Debugger
ASP Built-in Run-time Objects
Creating and Managing Cookies
Managing Sessions with and without Cookies
►scrrun.dll - Scripting Runtime DLL
What Is scrrun.dll?
"Dictionary" Class - Collection of Key-Value Pairs
"FileSystemObject" Class - File System
"Drive" Class - Disk Drive
"Folder" Class - File Folder
"File" Class - File Folder
►"TextStream" Class - Input or Output Stream
Managing Response Header Lines
Calculation Speed and Response Time
ADO (ActiveX Data Object) DLL
Working with MS Access Database
Guest Book Application Example
PDF Printing Version