网络编程
位置:首页>> 网络编程>> Asp编程>> asp如何读取一个文件内容?

asp如何读取一个文件内容?

 来源:asp之家 发布时间:2009-11-19 17:23:00 

标签:文件,asp,fso

代码和说明如下:

<%
Const ForReading = 1    
 ' 设定常量       
Const Create = False 
' 输入输出模式
Dim FSO 
' FileSystemObject
Dim TS  
' TextStreamObject
Dim strLine  
' 用来存储行
Dim strFileName
' 用来储存文件名
' 以上四行声明局部变量
strFileName = Server.MapPath("textfile.txt")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(strFileName, ForReading, Create)
' 用Opentextfile方法打开文本文件Method to Open the text File
If not TS.AtEndOfStream Then                  
  Do While not TS.AtendOfStream            
    strLine = TS.ReadLine   
' 每次读出一行
    Response.Write strLine   
   ' 显示该行
    Response.Write "<br>"                  
  loop
' 循环
End If
TS.Close        
Set TS = Nothing
Set FSO = Nothing
' 关闭对象和局部变量并清空
%>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com