怎样用asp读取一个文本文件的内容? 这里介绍一种简便的读取一个文本文件的方法:
<!--Start of ASP Code---->
<%
'by James Seymour, http://jamesdot.org
Dim write
Dim fileSysObj, tf, read
' 读取文本read.txt
'获得文件名字
read = "read.txt"
'读取文件的完整路径
read = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath
(Request.ServerVariables("PATH_INFO")), "\")) & read
'新建一个fileSysObj对象
Set fileSysObj = createObject("s cripting.FileSystemObject")
'读取整个文本文件
IF (fileSysObj.FileExists(read)) Then
'如果文件存在,则打来并读取文件
Set tf = filesysobj.OpenTextFile(read, 1)
read = tf.ReadLine
tf.Close
ELSE
'如果找不到read.txt文件,则显示下面的信息!
read = "I can't find the file read.txt! So this is my default message."
END IF
%>
'在下面表格中显示read.txt
<div align="center">
<center>
<table border="0" width="40%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="#EEEECC"><%=read%>
</td>
</tr>
<tr>
<td width="100%">
<!-- End of the ASP -->
更多的asp读取一个文本文件的内容请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2006-12-2