最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何使用ASP TextStream对象
时间:2022-06-30 11:41:28 编辑:袖梨 来源:一聚教程网
在下面的例子,我们将创建一个新的文本文件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
%>
相关文章
- 超级机器人大战Y金钱帝王奖杯怎么解锁 10万CREDIT获取攻略 09-16
- 无主之地4支线我腿哪去了任务怎么做 支线我腿哪去了图文攻略 09-16
- 无主之地4支线零件何处寻怎么做 支线零件何处寻图文攻略 09-16
- 无主之地4支线嗡嗡作响怎么做 支线嗡嗡作响图文攻略 09-16
- 超级机器人大战Y10大必练机体推荐 最强机体排行榜(下) 09-16
- 原神月之一罗盘扫不到宝箱在哪 宝箱位置攻略 09-16