如何使用asp.net_如何使用ASP TextStream对象

更新时间:2016-05-05    来源:文本特效    手机版     字体:

【www.bbyears.com--文本特效】

在下面的例子,我们将创建一个新的文本文件test.txt和写一些文本。首先,我们创建一个FileSystemObject对象的实例,然后使用CreateTextFile方法创建一个新的文本文件。的CreateTextFile返回一个TextStream对象,我们将用来写一些文本文件。

<%
Dim objFSO, objTStream
"Create an instance of the FileSystemObject object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
"Create a text file named myFile.txt, replacing any existing one with the same name
Set objTStream = objFSO.CreateTextFile("C: est.txt", True)
"Write some text to the file
objTStream.WriteLine("WebCheatSheet ASP Tutorials!")
objTStream.WriteBlankLines(1)
objTStream.WriteLine("The TextStream Object")
objTStream.WriteBlankLines(2)
objTStream.WriteLine("The TextStream object provides sequential access to the contents of text files.")
"Close the TextStream object
objTStream.Close
"Free up resources
Set objTStream = nothing
Set objFSO = nothing
%>
在下面的例子中,我们会认真阅读Test.txt文件内容。首先,我们创建FileSystemObject对象的实例,然后使用OpenTextFile方法打开Test.txt文件进行读取。此方法返回一个TextStream对象,我们将用来从文件中读取数据。我们会遍历每次读一行文件。

<%
Dim objFSO, objTStream
"Create an instance of the FileSystemObject object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
"Opens for reading a text file named myFile.txt
Set objTStream = objFSO.OpenTextFile("C: est.txt", 1)
"Read one line at a time until the end of the file is reached
Do Until objTStream.AtEndOfStream
  Response.Write "Line " & objTStream.Line & ": " & objTStream.ReadLine & "
"
Loop
"Close the Textstream object
objTStream.Close
"Free up resources
Set objTStream = nothing
Set objFSO = nothing
%>

本文来源:http://www.bbyears.com/wangyetexiao/23642.html

猜你感兴趣

热门标签

更多>>

本类排行