最新下载
热门教程
- 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
%>
相关文章
- 如何交易5GASS币?2025OKX交易所高效攻略 06-16
- 《花亦山心之月》莹儿头像获得方法有哪些 06-16
- 最新2025币圈十大现货交易全球交易所TOP10-最安全虚拟币交易app币安推荐 06-16
- 《时光杂货店》人才推荐细节解读 06-16
- ZKJ、KOGE暴跌80%成积分“绞肉机”,币安Alpha还能玩吗? 06-16
- 《白荆回廊》鸢技能有哪些 06-16